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

RadGrid Excel-Like Filtering

5 Answers 165 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chaim
Top achievements
Rank 1
Chaim asked on 12 Nov 2015, 09:20 PM

Good day,

I was trying to use the FilterType="HeaderContext"

It works fine but whenever I have a GridDateTimeColumn I get an error just before the check list items requested event fires.

 

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.  For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request

My column is like this:

 

<telerik:GridDateTimeColumn DataField="FechaSolicitud"
                                                    DataFormatString="{0:yyyy-MM-dd hh:mm:ss tt}"
                                                    DataType="System.DateTime"
                                                    EditDataFormatString="{0:yyyy-MM-dd}"
                                                    FilterControlAltText="Filter FechaSolicitud column"
                                                    HeaderStyle-Width="200px"
                                                    HeaderText="Fecha de solicitud"
                                                    SortExpression="FechaSolicitud"
                                                    ReadOnly="true"
                                                    UniqueName="FechaSolicitud">
                            <HeaderStyle Width="200px"/>
                        </telerik:GridDateTimeColumn>

If I comment out that column, everything works fine, but I need that column, I think I can change all the columns to a bound column and use an edit item template to get what I need, but there are lots of columns and grids in different pages where I would like to use this kind of filters, is it possible to make it work without having to change a lot in each grid??

 

thanks

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.  For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request

5 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 17 Nov 2015, 09:54 PM
Hello,

I have prepared a sample runnable project using the code you provided, however, I was not able to replicate the error you encounter. You can find my test project attached. Also confirm that you are using the latest Q3 2015 SP1 version of the controls.

Regards,
Pavlina
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Chaim
Top achievements
Rank 1
answered on 20 Nov 2015, 10:42 PM

Hi Pavlina

 I've created a sample project using yours as base,(is a rar renamed as png, it says only images can be attached)

 basically, it is composed of 2 SQLDataSources, 1 grid, and 1 tabstrip (you may notice something wrong with thee project... I chosed the wrong language... but it runs, so maybe just use the cs and aspx...)

 When a Tab strip button is pressed, a rebind occurs to the grid...

When rebinding, the grid checks what tab is selected and loads one or the other data source.

 

When first loaded, the filters work fine, but after changing the tab the filters stop working (the popup doesn't appear)

And if changing the tab again will throw the error.

So there are 2 things that I can't figure out.... any help will be greatly appreciated.

 

thanks!

0
Chaim
Top achievements
Rank 1
answered on 20 Nov 2015, 10:45 PM

just in case... here are the contents of the files, I used the same web.config and database

 

home.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Home.aspx.cs" Inherits="_Default" %>
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html>
 
    <head id="Head1"
          runat="server">
        <title></title>
 
    </head>
    <body>
        <form id="form1"
              runat="server">
            <telerik:RadScriptManager ID="scriptManager1"
                                      runat="server"></telerik:RadScriptManager>
            <telerik:RadTabStrip ID="RtsPendientes"
                                 runat="server"
                                 ResolvedRenderMode="Classic"
                                 ontabclick="RtsPendientes_TabClick">
                <Tabs>
                    <telerik:RadTab runat="server"
                                    Selected="True"
                                    Text="Aprobación"
                                    Value="aprobacion">
                    </telerik:RadTab>
                    <telerik:RadTab runat="server"
                                    Text="FEI"
                                    Value="fei">
                    </telerik:RadTab>
                </Tabs>
            </telerik:RadTabStrip>
            <telerik:RadMultiPage ID="RmpPendientes"
                                  runat="server"
                                  SelectedIndex="0">
                <telerik:RadPageView ID="RpvPendientesAprobacion"
                                     runat="server">
                </telerik:RadPageView>
                <telerik:RadPageView ID="RpvPendientesFei"
                                     runat="server">
 
                </telerik:RadPageView>
            </telerik:RadMultiPage>
            <telerik:RadGrid ID="RadGrid1"
                             runat="server"
                             AutoGenerateColumns="False"
                             AllowFilteringByColumn="True"
                             FilterType="HeaderContext"
                             EnableHeaderContextMenu="True"
                             EnableHeaderContextFilterMenu="True"
                             Height="100%"
                             GroupingEnabled="false"
                             PageSize="20"
                              
                OnFilterCheckListItemsRequested="RadGrid1_FilterCheckListItemsRequested"
                onneeddatasource="RadGrid1_NeedDataSource">
                <clientsettings allowcolumnhide="false"
                                enablerowhoverstyle="True">
                    <Selecting AllowRowSelect="True"/>
                </clientsettings>
                <MasterTableView commanditemdisplay="Top"
                                 DataKeyNames="EmployeeID"
                                 AllowFilteringByColumn="True"
                                 AllowPaging="True"
                                 AllowSorting="True"
                                 OverrideDataSourceControlSorting="True">
                    <Columns>
                        <telerik:GridDateTimeColumn DataField="HireDate"
                                                    FilterCheckListEnableLoadOnDemand="true"
                                                    DataFormatString="{0:yyyy-MM-dd hh:mm:ss tt}"
                                                    DataType="System.DateTime"
                                                    EditDataFormatString="{0:yyyy-MM-dd}"
                                                    FilterControlAltText="Filter HireDate column"
                                                    HeaderStyle-Width="200px"
                                                    HeaderText="Fecha de solicitud"
                                                    SortExpression="HireDate"
                                                    ReadOnly="true"
                                                    UniqueName="FechHireDateaSolicitud">
                            <HeaderStyle Width="200px"/>
                        </telerik:GridDateTimeColumn>
                    </Columns>
                </MasterTableView>
            </telerik:RadGrid>
            <asp:SqlDataSource ID="SqlDataSource1"
                               runat="server"
                               ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                               SelectCommand="SELECT * FROM [Employees]"></asp:SqlDataSource>
                                
            <asp:SqlDataSource ID="SqlDataSource2"
                               runat="server"
                               ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                               SelectCommand="SELECT * FROM [Employees]"></asp:SqlDataSource>
 
        </form>
    </body>
</html>
 

 

 

home.aspx.cs

 

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
 
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
 
    }
    protected void RadGrid1_FilterCheckListItemsRequested(object sender, GridFilterCheckListItemsRequestedEventArgs e)
    {
        string DataField = (e.Column as IGridDataColumn).GetActiveDataField();
 
        e.ListBox.DataSource = GetDataTable(DataField);
        e.ListBox.DataKeyField = DataField;
        e.ListBox.DataTextField = DataField;
        e.ListBox.DataValueField = DataField;
        e.ListBox.DataBind();
    }
    public DataTable GetDataTable(string field)
    {
        string query = string.Format("SELECT DISTINCT {0} FROM Employees", field);
 
        String ConnString = ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
        SqlConnection conn = new SqlConnection(ConnString);
        SqlDataAdapter adapter = new SqlDataAdapter();
        adapter.SelectCommand = new SqlCommand(query, conn);
 
        DataTable myDataTable = new DataTable();
 
        conn.Open();
        try
        {
            adapter.Fill(myDataTable);
        }
        finally
        {
            conn.Close();
        }
 
        return myDataTable;
    }
    protected void RtsPendientes_TabClick(object sender, RadTabStripEventArgs e)
    {
        bool aprobacion = true;
        switch (e.Tab.Value)
        {
            case "aprobacion":
                aprobacion = true;
 
                RadGrid1.Rebind();
                break;
            case "fei":
                aprobacion = false;
 
                RadGrid1.Rebind();
                break;
        }
    }
    protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        string tab = RtsPendientes.SelectedTab.Value;
 
        switch (tab)
        {
            case "aprobacion":
                RadGrid1.DataSource = SqlDataSource1;
                break;
            case "fei":
                RadGrid1.DataSource = SqlDataSource2;
                break;
            default:
                RadGrid1.DataSource = SqlDataSource1;
                break;
        }
    }
}
    

 

0
Chaim
Top achievements
Rank 1
answered on 23 Nov 2015, 04:23 PM
My telerik version is 2015.3.930.40
0
Accepted
Pavlina
Telerik team
answered on 23 Nov 2015, 04:51 PM
Hello,

We had some problems wiith excel-like filtering in Q3 2015 release, however they are already fixed, therefore 
I recommend you upgrade to the latest version (2015.3.1111) and let us know if you encounter any errors with it.

Regards,
Pavlina
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Chaim
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Chaim
Top achievements
Rank 1
Share this question
or