RadioButtonList 在按钮单击时丢失值
我在 ASPX GridView 的 dataItemTemplate 中有一个 RadioButtonList 。我想要 ButtonClick 事件上每个 RadioButtonList
的选定索引。在按钮单击事件中,radioButton 列表的 selectedIndex 为 -1。如何让我的 RadioList 记住用户在按钮单击事件中选择的值。
网格的 EnableCallbacks 为 true
网格的 Enableviewstate 为 true
RadioList 的 AutoPostBack 为 false。
<DataItemTemplate>
<dxe:ASPxRadioButtonList ID="m_RadioList" runat="server"
Border-BorderStyle="None" ClientInstanceName="RadioList"
OnInit="OnRadioListInit">
<Border BorderStyle="None" />
<Items>
<dxe:ListEditItem Text="M" Value="0" />
<dxe:ListEditItem Text="F" Value="1" />
<dxe:ListEditItem Text="NA" Value="2" />
</Items>
</dxe:ASPxRadioButtonList>
</DataItemTemplate>
protected void OnASPxButtonClick(object sender, EventArgs e)
{
for (int row = 0; row < m_ASPxGridView.VisibleRowCount; row++)
{
ASPxRadioButtonList radio = m_AccessPoint_UsersASPxGridView.FindRowCellTemplateControl(row,null, "m_RadioList") as ASPxRadioButtonList;
int r = (int) radio.SelectedIndex;
}
}
I have a RadioButtonList
in the dataItemTemplate of the ASPX GridView
. I want the selected index for each RadioButtonList
on the ButtonClick event. On the button click event the selectedIndex for the radioButton list is -1. How do I make my RadioList remember the user selected values in the button click event.
EnableCallbacks for grid is true
Enableviewstate for grid is true
AutoPostBack for RadioList is false.
<DataItemTemplate>
<dxe:ASPxRadioButtonList ID="m_RadioList" runat="server"
Border-BorderStyle="None" ClientInstanceName="RadioList"
OnInit="OnRadioListInit">
<Border BorderStyle="None" />
<Items>
<dxe:ListEditItem Text="M" Value="0" />
<dxe:ListEditItem Text="F" Value="1" />
<dxe:ListEditItem Text="NA" Value="2" />
</Items>
</dxe:ASPxRadioButtonList>
</DataItemTemplate>
protected void OnASPxButtonClick(object sender, EventArgs e)
{
for (int row = 0; row < m_ASPxGridView.VisibleRowCount; row++)
{
ASPxRadioButtonList radio = m_AccessPoint_UsersASPxGridView.FindRowCellTemplateControl(row,null, "m_RadioList") as ASPxRadioButtonList;
int r = (int) radio.SelectedIndex;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的网格可能会在页面加载中再次绑定,这就是为什么您的单选按钮列表也再次绑定,并且您将丢失所选值。确保在页面加载时绑定在
if(!Page.IsPostBack)
下。Your grid might bind again in your page load, and that's why your radiobuttonlist also bound again, and you are losing your selected value. Make sure you bind under
if(!Page.IsPostBack)
in your page load.如果您想在页面加载时绑定 GridView ,最好的办法是在读取
RadioButtonList
的databind
之前调用一个函数您的 GridView 并将其保存在静态 DataTable 中The best thing to do if you want to bind the
GridView
on page load, is to call a function before thedatabind
that reads theRadioButtonList
in yourGridView
and save it in a staticDataTable