开发者

RadioButtonList loses value on button Click

开发者 https://www.devze.com 2023-02-22 18:49 出处:网络
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

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;
    }开发者_JAVA百科
}


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.


The best thing to do if you want to bind the GridView on page load, is to call a function before the databind that reads the RadioButtonList in your GridView and save it in a static DataTable

0

精彩评论

暂无评论...
验证码 换一张
取 消