我有一个单选按钮列表,其中包含两个项,now.Here是aspx代码:
<asp:RadioButtonList ID="RadioButtonList1" runat="server" Font-Bold="True"
Height="52px" Width="181px" AutoPostBack="True" EnableTheming="True"
EnableViewState="true" onselectedindexchanged="RadioButtonList1_SelectedIndexChanged">
<asp:ListItem Value="Head of family "></asp:ListItem>
<asp:ListItem Value="Show all">All Family Members</asp:ListItem>
</asp:RadioButtonList>
在第一次加载页面时,我已经通过以下代码将第一个单选项设置为选定项:
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!IsPostBack)
{
RadioButtonList1.Items[0].Selected = true;
}
}
catch (Exception ce)
{
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + ce.Message + "');", true);
}
}
但是,在所有这一切之后,选择索引更改事件不会触发。我尝试将EnableViewState属性设置为针对radiobuttonlist和页面的true。我还尝试设置通过aspx代码选择的第一项,而不是在页面加载时执行,但不应该执行任何worked.What ?这是selectedindexchanged事件:
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
}
第一个项目被选中,没有问题,但是当我尝试选择第二个元素时,除了回发之外,什么都不会发生。我尝试在页面中添加两个单选按钮,看看它们是否有效,或者not.Even简单单选按钮在我添加复选框时没有响应selections.However,它们正常工作。
发布于 2015-01-08 13:31:42
如果在后面的代码中选择项,则事件不会触发。
来自MSDN:
当列表控件中的选择在发送到服务器之间发生更改时,将引发SelectedIndexChanged事件。
这里有更多的信息:
发布于 2015-01-08 14:40:10
从onselectedindexchanged="RadioButtonList1_SelectedIndexChanged"
控件中删除RadioButtonList
并尝试添加
RadioButtonList1.SelectedIndexChanged += new EventHandler(RadioButtonList1_SelectedIndexChanged);
在Page_Load
之外
if (!IsPostBack)
{
}
区块。看看能不能。
https://stackoverflow.com/questions/27841199
复制相似问题