首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

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

2012-01-16 
点击DropDownList1的一个值怎么让DropDownList2的值发生变化protected void DropDownList2_SelectedIndexC

点击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> 

热点排行