RadGrid Header Checkbox Find

3 posts, 0 answers
  1. Madhan
    Madhan avatar
    14 posts
    Member since:
    Aug 2012

    Posted 14 Aug 2012 Link to this post

    Hi - I am new to telerik controls. I have added a checkbox in Radgrid column header. In the code behing trying to find the column header checkbox control.

    My code:

    <telerik:RadGrid ID="RadGrid1" Width="97%"
                AllowPaging="True" PageSize="15" runat="server" AllowSorting="True" AllowFilteringByColumn="True" 
                GridLines="None">
                <MasterTableView Width="100%" AutoGenerateColumns="False" DataKeyNames="GrowerId">
                     <Columns>
                         <telerik:GridTemplateColumn UniqueName="TemplateColumn" SortExpression="CompanyName">
                         <HeaderTemplate
                                            <asp:CheckBox id="headerChkbox" OnCheckedChanged="chkHeader_CheckedChanged"  AutoPostBack="true" runat="server" Text="Select All" ></asp:CheckBox
                                           </HeaderTemplate
    var chkHeader = RadGrid1.MasterTableView.GetColumn("headerChkbox").HeaderAbbr = "checkbox";
     


    I was trying that chkHeader code. it says cannot find uniquename headerChkbox. Please help
  2. Madhan
    Madhan avatar
    14 posts
    Member since:
    Aug 2012

    Posted 14 Aug 2012 Link to this post

    Right now , I have code in code behind as

    oreach (GridHeaderItem headerItem in RadGrid1.MasterTableView.GetItems(GridItemType.Header))
            {
                CheckBox chk = (CheckBox)headerItem["TemplateColumn"].Controls[0]; // Get the header checkbox 
            }

    I am trying to find contrrol of checkbox that is placed in radgrid column header. I am getting error "
    Unable to cast object of type 'System.Web.UI.LiteralControl' to type 'System.Web.UI.WebControls.CheckBox'." Can anyone please help me fix this?
  3. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 15 Aug 2012 Link to this post

    Hi,

    Try accessing the CheckBox using FindControl method.
    C#:
    foreach (GridHeaderItem headerItem in RadGrid1.MasterTableView.GetItems(GridItemType.Header))
    {
        CheckBox chk = (CheckBox)headerItem.FindControl("headerChkbox");
    }

    Thanks,
    Shinu.
Back to Top