<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
            <asp:ListItem Value="1">张三</asp:ListItem>
            <asp:ListItem Value="2">李四</asp:ListItem>
            <asp:ListItem Value="2">王五</asp:ListItem>
</asp:DropDownList>

注意看上面3个项的text分别是张三,李四,王五;但value为1,2,2. 李四与王五的value是一样的。

现在执行selectedindexchanged事件:

 protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        string aaa = DropDownList1.SelectedItem.Text;
    }

当选择"王五"这一项时,奇怪的事发生了,aaa的值为"李四",而且页面上的DropDownList的的选择项也自动变成了"李四"。

经过调试发现,当选择"王五"这一项时,SelectedIndex为1,而不是2。而且这时当我选择"李四"或"王五"时,都不会触发

DropDownList1_SelectedIndexChanged事件,那么这个事件到底应该叫SelectedIndexChanged还是叫Selected'Value'Changed呢?

相关文章:

  • 2022-03-01
  • 2021-09-28
  • 2021-12-04
  • 2022-01-18
  • 2022-01-27
  • 2021-08-25
  • 2021-08-06
  • 2022-12-23
猜你喜欢
  • 2021-07-24
  • 2021-06-17
  • 2022-12-23
  • 2022-12-23
  • 2021-10-13
  • 2021-12-22
相关资源
相似解决方案