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

acces header template checkbox on button click outside the grid

1 Answer 20 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Savyo
Top achievements
Rank 1
Savyo asked on 19 Jul 2013, 12:25 PM

 Hi

     How can I acces the header template checkbox in client click of a button outside the grid.
 thanks for any help
Savyo

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 19 Jul 2013, 12:28 PM
Hi,

Please try the following code snippet to access the CheckBox in header template.

ASPX:
<telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1" runat="server" AutoGenerateColumns="false"
    OnItemCreated="RadGrid1_ItemCreated">
    <MasterTableView>
        <Columns>
            <telerik:GridTemplateColumn HeaderText="templ" AllowFiltering="true">
                <HeaderTemplate>
                    <asp:CheckBox ID="chkSelectAll" runat="server" />
                </HeaderTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>
<asp:HiddenField ID="HiddenField1" runat="server" />
<asp:Button ID="Button1" runat="server" Text="AccessHeader" OnClientClick="OnClientClick(); return false;" />

C#:
protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridHeaderItem)
    {
        GridHeaderItem hItem = (GridHeaderItem)e.Item;
        CheckBox chk1 = (CheckBox)hItem.FindControl("chkSelectAll");
        HiddenField1.Value = chk1.ClientID.ToString();
    }
}

Javascript:
<script type="text/javascript">
    function OnClientClick() {
        var masterTable = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
        var hidden = document.getElementById("HiddenField1");
        var checkBox = document.getElementById(hidden.value); // accessing the header Checkbox
        checkBox.checked = true; //checking the header checkbox
    }
</script>

Thanks,
Princy
Tags
Grid
Asked by
Savyo
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Share this question
or