sab669
sab669

Reputation: 4104

How to detect when a radio button in a DataGrid is selected?

I have a DataGrid on my webapge that looks like this:

<asp:datagrid id="dgCodes" runat="server" bodyHeight="300px" CssClass="tblScroll" Width="100%">
    <Columns>
        <asp:TemplateColumn ItemStyle-HorizontalAlign="Center" HeaderStyle-CssClass="clsGridHeaderText"
            HeaderStyle-Wrap="False" HeaderStyle-Width="10%" ItemStyle-Width="10%">
            <HeaderTemplate>
                Select
            </HeaderTemplate>
            <ItemTemplate>
                <INPUT type="radio" name="chkSelect"  TabIndex="-1" value='<%# DataBinder.Eval(Container, "DataItem.Code") %>' onclick="mfpSetCode(this);"  <%# mfpDisable(DataBinder.Eval(Container, "DataItem.Code")) %>>
            </ItemTemplate>
        </asp:TemplateColumn>
    </Columns>
</asp:datagrid>

So there's 1 radio button column titled "Select", and then a few columns get added once the data is bound to the DataGrind.

When the user selects a radio button in this DataGrid, it's supposed to populate 2 child DataGrids, using a unique value in one of the bound columns.

I was able to set a SelectedIndexChanged event for the grid, hoping that'd catch the selection of the radio button column and then I could get the data that way, but it does not.

How can I get some data when a RB is selected like this?

Upvotes: 0

Views: 1071

Answers (1)

j.f.
j.f.

Reputation: 3949

Use an <asp:RadioButton> instead. This will give you the OnCheckChanged event.

<asp:RadioButton ID="rbSelect" runat="server"
    Text='<%# DataBinder.Eval(Container, "DataItem.Code") %>'
    OnCheckChanged="rbSelect_CheckChanged"
    AutoPostBack="true" />

Then handle the event in your code behind.

Protected Sub rbSelect_CheckChanged(ByVal sender As Object, ByVal e As EventArgs)
{

}

Upvotes: 1

Related Questions