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

2 posts, 0 answers
  1. Priyanka
    Priyanka avatar
    34 posts
    Member since:
    Dec 2014

    Posted 12 Dec 2014 Link to this post

    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">
                            <telerik:GridNumericColumn DataField="Id" HeaderText="Id" HeaderStyle-Width="100px" AllowFiltering="False" FilterControlWidth="50px">
                             <telerik:GridTemplateColumn UniqueName="" HeaderText="Select">
                                            <asp:RadioButton ID="rbdSelect" runat="server" AutoPostBack="true" OnCheckedChanged="rbdSelect_CheckedChanged"></asp:RadioButton>
    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();
    Please reply what is wrong in my code
  2. Eyup
    Eyup avatar
    3801 posts

    Posted 17 Dec 2014 Link to this post

    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);" %>'>
    Copy Code
    function radioListClick(radioList) {

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


    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.

Back to Top