4 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 24 May 2011, 07:18 AM
Hello Anthony,
I am not quite sure about your requirement. I suppose you want this functionality in GridClientSelectColumn. If that is the requirement access CheckBox and then set Checked property as true in the RowSelecting event. You cannot directly access the HeaderTemplate controls. One suggestion is to save the CheckBoxcontrol ID in the Hidden Field and then from the ItemCreatedEvent, access the CheckBox using the HiddenField value.
aspx:
C#:
Javascript:
Thanks,
Princy.
I am not quite sure about your requirement. I suppose you want this functionality in GridClientSelectColumn. If that is the requirement access CheckBox and then set Checked property as true in the RowSelecting event. You cannot directly access the HeaderTemplate controls. One suggestion is to save the CheckBoxcontrol ID in the Hidden Field and then from the ItemCreatedEvent, access the CheckBox using the HiddenField value.
aspx:
<MasterTableView DataKeyNames="EmpId" CommandItemDisplay="Top"> <Columns> <telerik:GridClientSelectColumn HeaderText="chkbox" UniqueName="CheckBoxColumn"> </telerik:GridClientSelectColumn> . . . . </Columns></MasterTableView> <ClientSettings > <ClientEvents OnRowSelecting="OnRowSelecting" /> <Selecting AllowRowSelect="true" /> </ClientSettings>C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) { if (e.Item is GridHeaderItem) { GridHeaderItem item = (GridHeaderItem)e.Item; CheckBox chkbox = (CheckBox)item["CheckBoxColumn"].Controls[0]; HiddenField1.Value = chkbox.ClientID.ToString(); } }Javascript:
<script type="text/javascript"> function OnRowSelecting()
{ var hidden = document.getElementById("HiddenField1"); var chkbox = document.getElementById(hidden.value); chkbox.checked = true; }</script>Thanks,
Princy.
0
Anthony
Top achievements
Rank 2
answered on 24 May 2011, 07:38 AM
Hello Sir,
Thanks for the reply.
The checkbox I am asking for is on a HeaderTemplate Column, this control if checked will select (using a checkbos also) all the items on the grid. To make this explanation better, please see my snippet below:
Regards,
Anthony
Thanks for the reply.
The checkbox I am asking for is on a HeaderTemplate Column, this control if checked will select (using a checkbos also) all the items on the grid. To make this explanation better, please see my snippet below:
<Columns><telerik:GridTemplateColumn UniqueName="chkAllergen" DefaultInsertValue=""> <ItemTemplate> <asp:CheckBox ID="chkAllergen" runat="server" Style="position: relative" AutoPostBack="true" OnCheckedChanged="chkLinkAllergen_CheckedChanged" /> </ItemTemplate> <ItemStyle Width="50px" /> <HeaderTemplate> <asp:CheckBox ID="chkAll" runat="server" Style="position: relative" AutoPostBack="true" OnCheckedChanged="chkAllLinkAllergen_CheckedChanged"/> </HeaderTemplate> </telerik:GridTemplateColumn>
............ Regards,
Anthony
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 24 May 2011, 08:40 AM
Hi Anthony,
Thanks,
Jayesh Goyani
<telerik:GridTemplateColumn UniqueName="chkAllergen" DefaultInsertValue=""> <ItemTemplate> <asp:CheckBox ID="chkAllergen" runat="server" Style="position: relative" AutoPostBack="true" OnCheckedChanged="chkLinkAllergen_CheckedChanged" /> </ItemTemplate> <HeaderTemplate> <asp:CheckBox ID="chkAll" runat="server" Style="position: relative" AutoPostBack="true" OnCheckedChanged="chkAllLinkAllergen_CheckedChanged" /> </HeaderTemplate> </telerik:GridTemplateColumn>protected void chkLinkAllergen_CheckedChanged(object sender, EventArgs e) { int count = 0; foreach (GridDataItem item in grdActionMenu.MasterTableView.Items) { CheckBox chkAllergen = (CheckBox)item.FindControl("chkAllergen"); if (chkAllergen.Checked) { count++; } } foreach (GridHeaderItem headerItem in grdActionMenu.MasterTableView.GetItems(GridItemType.Header)) { CheckBox chk = (CheckBox)headerItem["chkAllergen"].Controls[1]; // Get the header checkbox if (grdActionMenu.MasterTableView.Items.Count == count) { chk.Checked = true; } else { chk.Checked = false; } } } protected void chkAllLinkAllergen_CheckedChanged(object sender, EventArgs e) { CheckBox chkAll = sender as CheckBox; foreach (GridDataItem item in grdActionMenu.Items) { CheckBox chkAllergen = (CheckBox)item.FindControl("chkAllergen"); chkAllergen.Checked = chkAll.Checked; } }Thanks,
Jayesh Goyani
0
Anthony
Top achievements
Rank 2
answered on 24 May 2011, 08:50 AM
Thanks Jayesh,
That's somehow help me achieve my goal. I just extracted some of your code, analyze then bingo!! Thanks a lot!!!
Regards
Anthony
That's somehow help me achieve my goal. I just extracted some of your code, analyze then bingo!! Thanks a lot!!!
Regards
Anthony