3 Answers, 1 is accepted
I tried following aproach for acheiving this functionality. Give a try with this and see whether it helps.
CS:
| protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) |
| { |
| if (e.Item is GridHeaderItem) |
| { |
| GridHeaderItem headerItem = (GridHeaderItem)e.Item; |
| CheckBox chk1 = new CheckBox(); |
| chk1.ID = "CheckBox1"; |
| chk1.Checked = true; |
| chk1.AutoPostBack = true; |
| chk1.CheckedChanged += new EventHandler(chk1_CheckedChanged); |
| headerItem["CategoryID"].Controls.Add(chk1); // Attach the checkbox to CategoryID column |
| CheckBox chk2 = new CheckBox(); |
| chk2.ID = "CheckBox2"; |
| chk2.Checked = true; |
| chk2.AutoPostBack = true; |
| chk2.CheckedChanged += new EventHandler(chk2_CheckedChanged); |
| headerItem["CategoryName"].Controls.Add(chk2); // Attach checkbox to CategoryName column |
| CheckBox chk3 = new CheckBox(); |
| chk3.ID = "CheckBox3"; |
| chk3.Checked = true; |
| chk3.AutoPostBack = true; |
| chk3.CheckedChanged += new EventHandler(chk3_CheckedChanged); |
| headerItem["Description"].Controls.Add(chk3); //Attach the checkbox to Description column |
| . . . |
| } |
| } |
| protected void chk1_CheckedChanged(object sender, EventArgs e) |
| { |
| CheckBox chk = (CheckBox)sender; |
| GridTableHeaderCell cell = (GridTableHeaderCell)chk.Parent; |
| if (cell.Text == "CategoryID") |
| { |
| RadGrid1.MasterTableView.Columns.FindByUniqueName("CategoryID").Display = false; |
| } |
| } |
| protected void chk2_CheckedChanged(object sender, EventArgs e) |
| { |
| CheckBox chk = (CheckBox)sender; |
| GridTableHeaderCell cell = (GridTableHeaderCell)chk.Parent; |
| if (cell.Text == "CategoryName") |
| { |
| RadGrid1.MasterTableView.Columns.FindByUniqueName("CategoryName").Display = false; |
| } |
| } |
| protected void chk3_CheckedChanged(object sender, EventArgs e) |
| { |
| CheckBox chk = (CheckBox)sender; |
| GridTableHeaderCell cell = (GridTableHeaderCell)chk.Parent; |
| if (cell.Text == "Description") |
| { |
| RadGrid1.MasterTableView.Columns.FindByUniqueName("Description").Display = false; |
| } |
| } |
Thanks,
Princy.
Thanks for quick response.
1)
Here :
if (cell.Text == "Name") in function
"chk1_CheckedChanged" is false. When i debug it i am getting cell.Text="". This is how i dinded the column named "Name".
<
telerik:GridBoundColumn DataField="Name" HeaderText="Name" SortExpression="Name"
UniqueName="Name">
<FilterTemplate>
<telerik:RadComboBox ID="rcbFilterIssueNames" runat="server" AutoPostBack="true" ShowToggleImage="true"
OnSelectedIndexChanged="rcbFilterIssueNames_SelectedIndexChanged" Skin="Office2007" EnableLoadOnDemand="true"
Width="300" Height="205" OnItemsRequested="rcbFilterIssueNames_ItemsRequested">
</telerik:RadComboBox>
</FilterTemplate>
</telerik:GridBoundColumn>
2) If i use in this way i will not able to get back the disabled column back, because i ll not be able to see it again until next pageload.
I need to have checkboxes on top of grid with unique name. So that i can check it or uncheck it.
Can you please help on this.
Thanks,
Josh.
Finally solved the above issue as follows. But this programming is done at serverside. Can any one help the same to write at client side using script.
<asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="true"
onselectedindexchanged="CheckBoxList1_SelectedIndexChanged" >
<asp:ListItem Text="Id" Selected="True"></asp:ListItem>
<asp:ListItem Text="Name" Selected="True"></asp:ListItem>
</asp:CheckBoxList>
.cs page :
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (ListItem listItem in CheckBoxList1.Items)
{
if (listItem.Selected)
{
rgIssues.MasterTableView.Columns.FindByUniqueName(listItem.Text).Display = true;
}
else
{
rgIssues.MasterTableView.Columns.FindByUniqueName(listItem.Text).Display = false;
}
}
}
Thanks,
Josh