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

RadGrid Header Checkbox Find

2 Answers 291 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Madhan
Top achievements
Rank 1
Madhan asked on 15 Aug 2012, 01:39 AM
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 Answers, 1 is accepted

Sort by
0
Madhan
Top achievements
Rank 1
answered on 15 Aug 2012, 03:09 AM
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?
0
Shinu
Top achievements
Rank 2
answered on 16 Aug 2012, 04:26 AM
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.
Tags
General Discussions
Asked by
Madhan
Top achievements
Rank 1
Answers by
Madhan
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or