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

How can I bind via codebehind an value to a checkbox

1 Answer 264 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Christian
Top achievements
Rank 1
Christian asked on 17 Mar 2009, 01:34 PM
I need to bind a value with codebehind to a checkbox.

I have build one checkbox for each row in the event ItemCreated

Christian

1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 18 Mar 2009, 05:07 AM
Hi Christian,

I would suggest you to use a GridCheckBoxColumn where you can bind the column with a boolean field. Or else you can use a GridTemplateColumn with a CheckBox in its ItemTemplate.

If you are using a GridTemplateColumn with a CheckBox in the ItemTemplate you can try the following code snippet to access the CheckBox in the code behind and bind it accordingly.

ASPX:

<
telerik:GridTemplateColumn UniqueName="TempCol" HeaderText="CheckBoxColumn"  > 
          <ItemTemplate> 
              <asp:CheckBox ID="CheckBox1" runat="server" /> 
          </ItemTemplate> 
        </telerik:GridTemplateColumn> 

CS:
   
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem dataItem = (GridDataItem)e.Item; 
            CheckBox chkbx = (CheckBox)dataItem["TempCol"].FindControl("CheckBox1"); 
            //you can bind the CheckBox here 
            //chkbx.Checked=true; 
             
        } 
    } 


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