This is a migrated thread and some comments may be shown as answers.

Get datakeyvalue/primary key of selected row upon clicking RadioButton inside RadGrid

1 Answer 66 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Priyanka
Top achievements
Rank 1
Priyanka asked on 12 Dec 2014, 06:41 AM
Trying to get the DataKeyValue/Primary key of selected row of RadGrid upon clicking Radiobutton

I tried below code but everytime its returning null in "string key"

<telerik:RadGrid ID="RadGrid1" EnableViewState="false" runat="server" AllowPaging="true" AllowSorting="False" AllowFilteringByColumn="true" GridLines="None" OnInit="RadGrid1_Init" OnDeleteCommand="RadGrid1_DeleteCommand">
        <ItemStyle Wrap="false"></ItemStyle>
         <MasterTableView AllowMultiColumnSorting="true" TableLayout="Fixed" DataKeyNames="Id" ClientDataKeyNames="Id">
                 <Columns>
                        <telerik:GridNumericColumn DataField="Id" HeaderText="Id" HeaderStyle-Width="100px" AllowFiltering="False" FilterControlWidth="50px">
                         <telerik:GridTemplateColumn UniqueName="" HeaderText="Select">
                                <ItemTemplate>
                                        <asp:RadioButton ID="rbdSelect" runat="server" AutoPostBack="true" OnCheckedChanged="rbdSelect_CheckedChanged"></asp:RadioButton>
                                 </ItemTemplate>
                          </telerik:GridTemplateColumn>
                  </Columns>
            </MasterTableView>
protected void rbdSelect_CheckedChanged(object sender, EventArgs e)
        {          
            foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
            {
                RadioButton rbd = (RadioButton)item.FindControl("rbdSelect");
                if (rbd.Checked == true)
                {
                    string key = item.GetDataKeyValue("Id").ToString();
                    Response.Redirect("~/Default.aspx");
                }
            }
        }
Please reply what is wrong in my code

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 17 Dec 2014, 06:49 AM
Hi Priyanka,

You can achieve that using the following approach:
Copy Code
protected void rbtnlStatus_SelectedIndexChanged(object sender, EventArgs e)
{
    GridDataItem item = (sender as RadioButtonList).NamingContainer as GridDataItem;
    item.Selected = true;
}

If you want to implement this logic on the client-side for better performance, you can add the following:
Copy Code
<asp:RadioButtonList ... onclick='<%# "radioListClick(this);" %>'>
JavaScript:
Copy Code
function radioListClick(radioList) {
    ...
}

Hope this helps.
Please give it a try and let me know about the result.

Regards,
Eyup
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
General Discussions
Asked by
Priyanka
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or