当前位置: 代码迷 >> ASP.NET >> 点击DropDownList1的一个值如何让DropDownList2的值发生变化
  详细解决方案

点击DropDownList1的一个值如何让DropDownList2的值发生变化

热度:2599   发布时间:2013-02-25 00:00:00.0
点击DropDownList1的一个值怎么让DropDownList2的值发生变化
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
  {
  if (DropDownList2.SelectedIndex == 2)
  {
  DropDownList3.Items[0].Value = "dd".ToString();
  DropDownList3.Items[1].Value = "dd".ToString();
  }
  }
在这个事件里写不对啊!该怎么做 啊

------解决方案--------------------------------------------------------
首先,DropDownList1的AutoPostBack属性应该设置为Ture
然后,如果你想改变显示的值,需要如下代码
DropDownList3.Items[0].Text = "dd".ToString();
DropDownList3.Items[0].Value = "dd".ToString();
DropDownList3.Items[1].Text = "dd".ToString();
DropDownList3.Items[1].Value = "dd".ToString();
------解决方案--------------------------------------------------------
HTML code
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged">    <asp:ListItem Value="0">请选择</asp:ListItem>    <asp:ListItem Value="China">中国</asp:ListItem>    <asp:ListItem Value="USA">美国</asp:ListItem>           </asp:DropDownList><asp:DropDownList ID="DropDownList3" runat="server">    <asp:ListItem Value="0">请选择</asp:ListItem></asp:DropDownList>