【发布时间】:2020-03-18 14:02:42
【问题描述】:
我有一个:
RadioButtonList 默认选择第一项。
取消选择此选项的链接按钮。
LinkButton 显示 RadioButtonList 的索引
如果我单击取消选择,然后单击保存,则会显示第一项的索引 0。这种看似错误的行为是由于重新加载页面并根据默认设置进行选择的回发造成的。
但是:如果我现在选择 List 的 Item2 然后单击保存,我希望回发将 RadioButtonList 重置为其初始值时会出现相同的行为。但显示 List-Item2 的索引 1。
所以“未选择”在回发时被否决,而“已选择”则不是! 真的是这样吗?令人困惑且难以处理。
<asp:RadioButtonList ID="RBL_SelectType" runat="server">
<asp:ListItem Text="Choice1" Value="0" Selected="True" />
<asp:ListItem Text="Choice2" Value="1" />
</asp:RadioButtonList>
<asp:LinkButton ID="LB_Reset" runat="server" OnClick="Unselect">unselect RBL</asp:LinkButton>
<asp:LinkButton ID="LB_Save" runat="server" OnClick="Save">Save</asp:LinkButton>
<asp:Label runat="Server" ID="Message" />
与:
protected void Save(object sender, EventArgs e)
{
Message.Text = "Index = " + Convert.ToString(RBL_SelectType.SelectedIndex);
}
protected void Unselect(object sender, EventArgs e)
{
RBL_RBL_SelectType.SelectedIndex = -1;
}
【问题讨论】:
-
你有 Page_Load 事件吗?
-
不,我为这次测试扯掉了所有东西
标签: c# asp.net postback radiobuttonlist