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

How to check a checkbox on other button's click event

5 Answers 587 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Omarr
Top achievements
Rank 1
Omarr asked on 29 Oct 2008, 02:05 PM
The requirement is simple. But...
I want to mark the checkboxes which exist as a template column in a grid on other button's click event.

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 30 Oct 2008, 05:18 AM
Hello,

You can try out the following code to checkmark the checkbox in the TemplateColumn on clicking a button. The code shows how to checkmark the checkbox for the row in which the button is clicked.
aspx:
 <telerik:GridTemplateColumn UniqueName="TemplateColumn3"
    <ItemTemplate> 
        <asp:CheckBox ID="CheckBox1" runat="server" /> 
    </ItemTemplate>            
 </telerik:GridTemplateColumn> 

cs:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    { 
        if (e.CommandName == "Check") 
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            CheckBox chk = (CheckBox)item.FindControl("CheckBox1"); 
            chk.Checked = true
        } 
    } 

Thanks
Princy.
0
Omarr
Top achievements
Rank 1
answered on 30 Oct 2008, 01:58 PM
What I understand from the code you provided that the button is also included in the same row. This is not what I require. There is another button, outside the grid which handles the checking of the checkboxes in a grid. There is some more logic which calculates the checkstate of checkboxes amd check/uncheck them accordingly.
0
Omarr
Top achievements
Rank 1
answered on 30 Oct 2008, 02:00 PM
And not to forget the checkboxes exist on the rows of the child grid. (I am using hierarchical grids)
0
Daniel
Telerik team
answered on 30 Oct 2008, 03:43 PM
Hello Omarr,

Please test the attached example.

Additionally I suggest you examine the following document:
Traversing detail tables/items in Telerik RadGrid

Regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Shinu
Top achievements
Rank 2
answered on 31 Oct 2008, 04:36 AM
Hi Omarr,

Try the following code snippet to achieve the desired scenario.

ASPX:
<DetailTables > 
   <telerik:GridTableView DataSourceID="SqlDataSource1"  Name="Detail"  runat="server" > 
     <Columns> 
        <telerik:GridTemplateColumn UniqueName="MyTempCol" > 
         <ItemTemplate> 
              <asp:CheckBox ID="CheckBox2" runat="server" /> 
         </ItemTemplate> 
        </telerik:GridTemplateColumn> 
     </Columns> 
   </telerik:GridTableView> 
 </DetailTables> 

CS:
protected void Button1_Click(object sender, EventArgs e) 
    { 
        foreach (GridItem item in RadGrid1.Items) 
        { 
            if (item.OwnerTableView.Name == "Detail") 
            { 
                GridDataItem childitem = (GridDataItem)item; 
                CheckBox chkbx2 = (CheckBox)childitem["MyTempCol"].FindControl("CheckBox2"); 
                chkbx2.Checked = !chkbx2.Checked; 
            } 
        } 
    } 


Regards
Shinu.
Tags
Grid
Asked by
Omarr
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Omarr
Top achievements
Rank 1
Daniel
Telerik team
Shinu
Top achievements
Rank 2
Share this question
or