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

Getting the id of the record for which the checkbox is enabled

1 Answer 72 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jinu
Top achievements
Rank 1
Jinu asked on 06 Jul 2011, 04:54 AM
Hello,

I am using a RadGrid with a Checkbox as the last column. Can you please provide me the code  to detect the checkbox event. My purpose is to collect the id of the record for which the check box is enabled.

Please help

Thanks in Advance

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 06 Jul 2011, 06:49 AM
Hello Jinu,

Here is the sample code that I tried to access CheckBox from client side and server side.

Clientside method:

aspx:
<telerik:GridTemplateColumn>
    <ItemTemplate>
          <asp:CheckBox ID="CheckBox1" runat="server" OnCheckedChanged="CheckBox1_CheckedChanged" AutoPostBack="true"  />
   </ItemTemplate>
</telerik:GridTemplateColumn>


C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
 {
        if (e.Item is GridDataItem)
        {
            GridDataItem item = (GridDataItem)e.Item;
            CheckBox chkbox = (CheckBox)item.FindControl("CheckBox1");
            int index = item.ItemIndex;//getting the index
            chkbox.Attributes.Add("onclick", "clickEvent('" + index + "');");//attaching client events from server side
        }
 }

Javascript:
<script type="text/javascript">
    function clickEvent(index)
   {
     alert(index);
   }
</script>


Also you can try the same from server side by attaching OnCheckedChanged event for CheckBox.

C#:
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
   {
       CheckBox chkbox = sender as CheckBox;
       GridDataItem item = (GridDataItem)(sender as CheckBox).NamingContainer;
       string emp = item["ColumnUniqueName"].Text.ToString();
    }

Thanks,
Shinu
Tags
Grid
Asked by
Jinu
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or