读书人

DropDownLis赋值的有关问题

发布时间: 2012-09-01 09:33:02 作者: rapoo

DropDownLis赋值的问题
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为请选择
这需要怎么写?请高手帮帮忙 我是小白 请尽量写清楚一些 谢谢了

[解决办法]
请选择 和 空其实是一样的,更智能的你可以通过控制 下拉框的可用与不可用来实现效果,比如当第一个下拉框选中值不为空时,打开第二个,否则,禁用第二个和第三个,如此类推
[解决办法]

HTML code
<%@ 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> 


[解决办法]
refer:
http://www.cnblogs.com/insus/archive/2011/07/04/2097059.html

读书人网 >asp.net

热点推荐