C# onselectindexchange事件未触发
在下面的代码中,当我选择一个值时,我有一个下拉列表。SelectedIndexChanged上的C# onselectindexchange事件未触发,c#,asp.net,C#,Asp.net,在下面的代码中,当我选择一个值时,我有一个下拉列表。SelectedIndexChanged上的没有触发事件。我已经尝试了,但无法得到预期的结果。有人能帮我吗 代码: <asp:DropDownList ID="cbAutoList" runat="server" CssClass="cbAutoList1" AutoPostBack="true"
没有触发事件。我已经尝试了,但无法得到预期的结果。有人能帮我吗
代码:
<asp:DropDownList ID="cbAutoList"
runat="server"
CssClass="cbAutoList1"
AutoPostBack="true"
OnSelectedIndexChanged="cbAutoList_SelectedIndexChanged">
<asp:ListItem Value="hai"></asp:ListItem>
<asp:ListItem Value="hello"></asp:ListItem>
</asp:DropDownList>
我刚刚测试了你的代码,它在我身边工作。请制作一个测试项目,并在Default.aspx
中尝试它的工作正常
protected void cbAutoList_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
if (cbAutoList.Items.Count > 0)
{
}
else
{
}
}
catch (Exception ex)
{
throw ex;
}
}
<asp:DropDownList ID="cbAutoList" runat="server" CssClass="cbAutoList1" AutoPostBack="true" OnSelectedIndexChanged="cbAutoList_SelectedIndexChanged">
<asp:ListItem Value="hai"></asp:ListItem>
<asp:ListItem Value="hello"></asp:ListItem>
</asp:DropDownList>
protectedvoid cbAutoList\u SelectedIndexChanged(对象发送方,事件参数e)
{
尝试
{
如果(cbAutoList.Items.Count>0)
{
}
其他的
{
}
}
捕获(例外情况除外)
{
掷骰子;
}
}
在aspx中,您只有一个列表项吗?如果只有一个元素,SelectedIndexChanged将如何激发?我已经检查了多个元素,但它没有激发。dropdownlist中只有一项。向下拉列表中添加更多listitems。我添加了多个它抛出的值。在DropDownList中不能选择多个项目。我已经检查了我的代码。工作正常。你从哪里得到这个错误??在pageload中,我正在将下拉列表绑定到datalist,这将是一个issue@user3224577首先,它必须启动事件。您尝试过这个吗?@Afnan Ahmad它没有触发事件。@user3224577您能在测试项目中尝试一下吗?我肯定你错过了一些东西。我刚刚检查了这个测试项目,它工作得很好。
protected void cbAutoList_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
if (cbAutoList.Items.Count > 0)
{
}
else
{
}
}
catch (Exception ex)
{
throw ex;
}
}
<asp:DropDownList ID="cbAutoList" runat="server" CssClass="cbAutoList1" AutoPostBack="true" OnSelectedIndexChanged="cbAutoList_SelectedIndexChanged">
<asp:ListItem Value="hai"></asp:ListItem>
<asp:ListItem Value="hello"></asp:ListItem>
</asp:DropDownList>