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

Uncheck checkbox in header of templatecolumn

4 Answers 47 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Shawn
Top achievements
Rank 1
Shawn asked on 25 Jun 2013, 09:20 PM
How do I uncheck a checkbox in the header of a template column on the client side from the RowDeselected event? Nothing I try seems to be able to access it correctly.

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 26 Jun 2013, 06:14 AM
Hi Shawn,

I'm not sure about your requirement.Please have a look at this code library.
Check/Uncheck all checkboxes in template column and selecting rows with checkbox

Thanks,
Princy
0
Shawn
Top achievements
Rank 1
answered on 26 Jun 2013, 11:16 AM
I have:
<telerik:GridTemplateColumn UniqueName="CheckBoxTemplateColumn" AllowFiltering="false">
<ItemTemplate>
<asp:CheckBox ID="chkSelectCol" runat="server" />
</ItemTemplate>
<HeaderTemplate>
<asp:CheckBox ID="headerChkbox" runat="server" onClick="ToggleSelectedState(this.checked)"/>
</HeaderTemplate>
</telerik:GridTemplateColumn>
as a column.

On the RowDeselected Event (
<ClientEvents OnRowDeselecting="RowDeselected"/> )

I want to get headerChkbox and uncheck it. How do I access headerChkbox?
0
Princy
Top achievements
Rank 1
answered on 27 Jun 2013, 04:40 AM
Hi Shawn,

Please try the following code snippet to uncheck header on row deselect.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" OnItemCreated="RadGrid1_ItemCreated">
    <MasterTableView>
        <Columns>         
            <telerik:GridTemplateColumn UniqueName="CheckBoxTemplateColumn" AllowFiltering="false">
                <ItemTemplate>
                    <asp:CheckBox ID="chkSelectCol" runat="server" />
                </ItemTemplate>
                <HeaderTemplate>
                    <asp:CheckBox ID="headerChkbox" runat="server" />
                </HeaderTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
    <ClientSettings Selecting-AllowRowSelect="true">
        <ClientEvents OnRowDeselected="RowDeselected" />
    </ClientSettings>
</telerik:RadGrid>
<asp:HiddenField ID="HiddenField1" runat="server" />

C#:
protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridHeaderItem)
    {
        GridHeaderItem head = (GridHeaderItem)e.Item;
        CheckBox check = (CheckBox)head.FindControl("headerChkbox"); //Access the headertemplate checkbox
        HiddenField1.Value = check.ClientID.ToString();    //Storing its ID in the hiddenfield to access it on ClientSide
    }
}

JS:
<script type="text/javascript">
 function RowDeselected()
   {          
    var hidden = document.getElementById("HiddenField1");
    var headercheck = document.getElementById(hidden.value);
    headercheck.checked = false;
   }
</script>

Thanks,
Princy
0
Shawn
Top achievements
Rank 1
answered on 27 Jun 2013, 12:35 PM
Thanks, I was actually going down that route but found that:

var chkBox= $('input[id$="headerChkBox"]');
chkBox[0].checked = false;
Works as well.
Tags
Grid
Asked by
Shawn
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Shawn
Top achievements
Rank 1
Share this question
or