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

Row selection by radio button

3 Answers 189 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ajith Nair
Top achievements
Rank 1
Ajith Nair asked on 17 Jan 2011, 05:09 PM
Hi,
Can anyone tell me how to select a radgrid row from client side by clicking a radio button.Beacuse I am taking the selected row in the code behind to save the data.
(Currently I am achieving this by a post back. I want to avoid post back so that I can make some client side validations.)

Or is there any way to get the datakey value from the checked radiobutton?

Thanks in advance
AJITH

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 18 Jan 2011, 05:43 AM
Hello Ajith,

Here is the sample code snippet to achieve your requirement.

ASPX:
<telerik:GridTemplateColumn>
    <ItemTemplate>
        <asp:RadioButton ID="RadioButton1" runat="server"  />
    </ItemTemplate>
</telerik:GridTemplateColumn>

C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
   {
      if (e.Item is GridDataItem)
       {
             GridDataItem item = (GridDataItem)e.Item;
             RadioButton rdbtn = (RadioButton)item.FindControl("RadioButton1");
             rdbtn.Attributes.Add("onclick","RadioButtonClick('"+item.ItemIndex+"');");
       }
   }

JavaScript:
<script type="text/javascript">
       function RadioButtonClick(itemindex) {
           var grid = $find("<%= RadGrid1.ClientID %>");
           var masterTable = grid.get_masterTableView();
           var row = masterTable.get_dataItems()[itemindex];
           row.set_selected(true);//selecting grid row
           var dataKeyValue = row.getDataKeyValue("EmployeeID");//accessing DataKeyValue
       }
   </script>
   

Thanks,
Princy.
0
yare
Top achievements
Rank 1
answered on 30 Aug 2011, 12:12 AM
Hello

i need something like this, but I want to save the data from the row in a variable can you tell me how can I do this?

thank you!!!!
0
Princy
Top achievements
Rank 2
answered on 30 Aug 2011, 05:32 AM
Hello Yare,

Take a look at the following help documentation which explains how to access cells and rows.
Accessing Cells and Rows.

Thanks,
Princy.
Tags
Grid
Asked by
Ajith Nair
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
yare
Top achievements
Rank 1
Share this question
or