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

6 posts, 0 answers
  1. Omarr
    Omarr avatar
    24 posts
    Member since:
    Sep 2008

    Posted 29 Oct 2008 Link to this post

    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.
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 30 Oct 2008 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Omarr
    Omarr avatar
    24 posts
    Member since:
    Sep 2008

    Posted 30 Oct 2008 Link to this post

    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.
  5. Omarr
    Omarr avatar
    24 posts
    Member since:
    Sep 2008

    Posted 30 Oct 2008 Link to this post

    And not to forget the checkboxes exist on the rows of the child grid. (I am using hierarchical grids)
  6. Daniel
    Admin
    Daniel avatar
    4945 posts

    Posted 30 Oct 2008 Link to this post

    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.
  7. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 30 Oct 2008 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017