protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            DataTable dt = getFL(0);            DropDownList1.DataSource = dt;
            DropDownList1.DataBind();
           
            DropDownList1.SelectedIndex = -1;         
        }
    }
    
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        string selectvalue = DropDownList1.SelectedValue;        DropDownList2.Items.Clear();
        if (DropDownList1.SelectedValue == "")
        {
            DropDownList2.Items.Add(new ListItem("请选择"));
            return;
        }
        int selectvalues = Convert.ToInt32(selectvalue);
        DataTable dt = getFL(selectvalues);
        DropDownList2.DataSource = dt;
        
        DropDownList2.DataBind(); 
        DropDownList2.SelectedIndex = 0;
   
    }  protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
    {
        string Selectvalue = DropDownList2.SelectedValue;
      
        DropDownList3.Items.Clear();
        if (DropDownList2.SelectedValue == "")
        {
            DropDownList3.Items.Add(new ListItem("请选择"));
            return;
        }
        int Selectvalues = Convert.ToInt32(Selectvalue);
        DataTable dt = getFL(Selectvalues);
        DropDownList3.DataSource = dt;
        DropDownList3.DataBind();   
    }  
我想在一开始的时候DropDownList1显示请选择,Drop2和Drop3为空,当Drop1选中后,Drop2显示为请选择,Drop3还是为空,Drop2选中时,Drop3为请选择
这需要怎么写?请高手帮帮忙  我是小白   请尽量写清楚一些  谢谢了

解决方案 »

  1.   


    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs" Inherits="WebTest.WebForm3" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:DropDownList ID="DropDownList1" runat="server" 
                onselectedindexchanged="DropDownList1_SelectedIndexChanged" AutoPostBack="true">
              <asp:ListItem Text="请选择" Value="0" Selected="True"></asp:ListItem>
              <asp:ListItem Text="项目1" Value="1"></asp:ListItem>
              <asp:ListItem Text="项目2" Value="2"></asp:ListItem>
              <asp:ListItem Text="项目3" Value="3"></asp:ListItem>
            </asp:DropDownList>        <asp:DropDownList ID="DropDownList2" runat="server" 
                onselectedindexchanged="DropDownList2_SelectedIndexChanged" AutoPostBack="true">
            <asp:ListItem Text=" " Value="-1" Selected="True"></asp:ListItem>
            <asp:ListItem Text="请选择" Value="0" ></asp:ListItem>
              <asp:ListItem Text="项目1" Value="1"></asp:ListItem>
              <asp:ListItem Text="项目2" Value="2"></asp:ListItem>
              <asp:ListItem Text="项目3" Value="3"></asp:ListItem>
            </asp:DropDownList>        <asp:DropDownList ID="DropDownList3" runat="server">
            <asp:ListItem Text=" " Value="-1" Selected="True"></asp:ListItem>
            <asp:ListItem Text="请选择" Value="0"></asp:ListItem>
              <asp:ListItem Text="项目1" Value="1"></asp:ListItem>
              <asp:ListItem Text="项目2" Value="2"></asp:ListItem>
              <asp:ListItem Text="项目3" Value="3"></asp:ListItem>
            </asp:DropDownList>
        </div>
        </form>
    </body>
    </html>using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;namespace WebTest
    {
        public partial class WebForm3 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {        }        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
            {
                if (DropDownList1.SelectedValue!="0")
                {
                    DropDownList2.SelectedValue = "0";
                }
                else
                {
                    DropDownList2.SelectedValue = "-1";
                }
            }        protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
            {
                if (DropDownList2.SelectedValue != "0")
                {
                    DropDownList3.SelectedValue = "0";
                }
            }
        }
    }
    DropDownList的数据绑定的话自己去写下就好了。
      

  2.   

    refer:
    http://www.cnblogs.com/insus/archive/2011/07/04/2097059.html