I have a RadGrid where the columns are autogenerated based on the DataSet. I need to check if one of the columns exists, I would like to make that column filtered by a combobox or a dropdown.I have a RadGrid where the columns are autogenerated based on the DataSet. I need to check if one of the columns exists, I would like to make that column filtered by a combobox or a dropdown.I have a RadGrid where the columns are autogenerated based on the DataSet. I need to check if one of the columns exists, I would like to make that column filtered by a combobox or a dropdown.
ASPX
Code Behind
MyFilterTemplate
The problem I am having is that I am getting an exception:
Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request.
Any suggestion on how to solve this?
ASPX
<telerik:RadGrid ID="rgApplications" runat="server" AllowSorting="True" AutoGenerateColumns="False" AllowPaging="True" GridLines="None" Width="100%" CellSpacing="0"> <MasterTableView DataKeyNames="ExecutedDocumentId,TemplateId,ParentId" ClientDataKeyNames="ExecutedDocumentId,TemplateId,ParentId" AutoGenerateColumns="true" AllowFilteringByColumn="true"> <EditFormSettings EditFormType="Template"> <EditColumn UniqueName="EditColumn"> </EditColumn> <FormTemplate> <div style="padding-bottom: 5px; padding-top: 5px; padding-left: 20px;"> <b><%# (Container is GridEditFormInsertItem) ? GetResource("Add") : GetResource("Edit") %></b> <table border="0" cellpadding="2" width="100%"> <tr> <td nowrap> <asp:Label ID="lblType" runat="server" resourcekey="Type" AssociatedControlID="ddlType" />: </td> <td nowrap align="left" style="padding-left: 5px"> <asp:DropDownList ID="ddlType" Width="340px" MaxLength="120" runat="server" /> <span style="color: Red; padding-left: 2px; padding-right: 3px; font-size: larger">*</span> <asp:RequiredFieldValidator ID="rfvType" ControlToValidate="ddlType" InitialValue="0" ValidationGroup="UpdateApplications" runat="server" ErrorMessage="Required" ForeColor="Red" /> </td> </tr> </table> <p> <asp:ImageButton ID="btnSaveApplications" runat="server" ValidationGroup="UpdateApplications" resourcekey="Save" CommandName="SaveApplication" /> <asp:ImageButton ID="btnCancelApplications" runat="server" resourcekey="Cancel" CommandName="Cancel" /> </p> </div> </FormTemplate> </EditFormSettings> <CommandItemSettings ShowRefreshButton="false" ShowAddNewRecordButton="true" /> <Columns> <telerik:GridClientSelectColumn UniqueName="SelectApplication" HeaderTooltip="Select All" /> <telerik:GridButtonColumn UniqueName="DeleteDocument" CommandName="DeleteDocument" ButtonType="ImageButton" ShowFilterIcon="false" /> <telerik:GridButtonColumn UniqueName="ViewDocument" CommandName="ViewDocument" ButtonType="ImageButton" ShowFilterIcon="false" /> </Columns> </MasterTableView></telerik:RadGrid>Code Behind
void rgApplications_ColumnCreated(object sender, GridColumnCreatedEventArgs e){ // Make Document Status Filter A DropDown if (e.Column.UniqueName == "DocumentStatus") { GridBoundColumn bCol = e.Column as GridBoundColumn; if (bCol != null) { Data.TaxonomyFilteringTemplate template = new MyFilteringTemplate(e.Column.UniqueName, "Document Status", rgApplications); bCol.FilterTemplate = template; bCol.CurrentFilterFunction = GridKnownFunction.EqualTo; } }}MyFilterTemplate
using System;using System.Collections.Generic;using System.Data;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using Telerik.Web.UI;namespace MyTestProgram{ public class MyFilteringTemplate : ITemplate { protected DropDownList combo; private string colname; private string lookupName; RadGrid radgrid; public TaxonomyFilteringTemplate(string cName, string lookup, RadGrid grid) { colname = cName; lookupName = lookup; radgrid = grid; } public void InstantiateIn(Control container) { combo = new DropDownList(); combo.ID = "RadComboBoxControl"; container.Controls.Add(combo); combo.AutoPostBack = true; //combo.EnableViewState = false; combo.SelectedIndexChanged += combo_SelectedIndexChanged; combo.Items.Add(new ListItem("Please Select")); var dt = MyController.GetLookupList(this.lookupName); var dvOptions = new DataView(dt); dvOptions.Sort = "Name"; foreach (DataRow dr in dvOptions.ToTable().Rows) { combo.Items.Add(new ListItem(dr["Name"].ToString())); } } void combo_SelectedIndexChanged(object sender, EventArgs e) { DropDownList ddl = sender as DropDownList; string filterExpression = string.Empty; if (ddl.Text != "") filterExpression = "([" + colname + "] = '" + ddl.Text + "')"; radgrid.MasterTableView.FilterExpression = filterExpression; radgrid.MasterTableView.Rebind(); } }}The problem I am having is that I am getting an exception:
Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request.
Any suggestion on how to solve this?
