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

How do I get a CheckBox in a RadGrid

2 Answers 63 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 19 Nov 2010, 04:52 PM
I have several checkboxes in a RadGrid and checkBoxe 4 does an AutoPostback to DoSomething(object obj, EventArgs e). 

This works great and I don't want change anything and I use datakeys to get my values from the row.  I also don't want to loop through GridDataItems to find out if checkbox 1-3 are checked.  

<telerik:GridTemplateColumn HeaderText="Comments" ItemStyle-HorizontalAlign="Left" HeaderStyle-Width="250px" Groupable="false" ItemStyle-VerticalAlign="Top" UniqueName="CheckBoxes">
  <ItemTemplate>                           
     <asp:CheckBox ID="CheckBox1" Text="CheckBox 1" runat="server" /><br /> 
     <asp:CheckBox ID="CheckBox2" Text="CheckBox 2" runat="server" /><br /> 
     <asp:CheckBox ID="CheckBox3" Text="ChcekBox 3" runat="server" /><br />
     <asp:CheckBox ID="CheckBox4" Text="CheckBox 4" OnCheckedChanged="DoSomething" AutoPostBack="True"  runat="server" />
  </ItemTemplate>
</telerik:GridTemplateColumn>

II would like to see of the checkboxes for 1-3 are checked, since checkbox 4 is firing the postback "DoSomething".
protected void DoSomething(object obj, EventArgs e)
 {
    CheckBox checkBox1 = (CheckBox)obj;
    GridDataItem checkedOffer = (obj as CheckBox).NamingContainer as GridDataItem;
     if ((obj as CheckBox).Checked)
        {
          // I need to find the other checkboxes in here when someone clicks on CheckBox 4
        }
 }

Thank you in advance!

2 Answers, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 19 Nov 2010, 11:01 PM
Hello Michael,

Please try the following:
protected void DoSomething(object obj, EventArgs e)
{
    TableCell cell = (obj as CheckBox).Parent as TableCell;
    foreach (Control ctrl in cell.Controls)
    {
        if (ctrl is CheckBox && (ctrl as CheckBox).Checked)
        {
            // I need to find the other checkboxes in here when someone clicks on CheckBox 4
        }
    }
}

Kind regards,
Daniel
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Mike
Top achievements
Rank 1
answered on 22 Nov 2010, 05:07 PM

Thanks Daniel, It works great!

CheckBox check = (CheckBox)cell.FindControl("CheckBox1");
string check2 = check.Text;

 

 

 

 

 

Tags
Grid
Asked by
Mike
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Mike
Top achievements
Rank 1
Share this question
or