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

Check filter state on postback

5 Answers 156 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ferdinand
Top achievements
Rank 1
Ferdinand asked on 02 May 2011, 09:22 AM
Hi there,
how do I get to know if a grid was filtered by a specified column on PostBack?
I use a programmatically created grid and it loses its filter textbox entry on every postback, but the filter is still active. So the user does not see a column is still filtered. I would like to refill the TextBox so I the user has a hint that the column is still filterd.

Thanks.
Ferdinand

5 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 04 May 2011, 02:11 PM
Hi Ferdinand,

You can check if the filter expression is different than empty string. This would mean the grid is filter.
However, the filter value and filter function should be maintained by the grid itself on post. A possible reason for the column filter value and function to be lost are if the columns of the programmatic grid are not added properly.
Can you share the code for creating the grid?

Additionally, you can check this topic and see if you followed the steps for defining grid structure dynamically.

Kind regards,
Iana
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Ferdinand
Top achievements
Rank 1
answered on 05 May 2011, 08:24 AM
Hi,
here is the code for the dynamically created grid:
        protected override void OnInit(EventArgs e)
        {
            createGrid();
            base.OnInit(e);
        }
 
private void createGrid()
        {
            RadGrid grid = new RadGrid();
            setGridProperties(grid);
            this.rgTreeList = grid;
            DataSet ds;
           ds = getData();
                if (ds == null)
                {
                    ds = new DataSet();
                    ds.Tables.Add();
                }
             
            createGridColumns(ds); // Creates the columns dynamically by the columns in the DataSet
             
            this.panelGrid.Controls.Clear();
            this.panelGrid.Controls.Add(grid);
            setGridEvents(grid);
            grid.DataSource = ds;
        }
 
private void setGridProperties(KanioGrid grid)
        {
            grid.ID = "rgTreeList";
            grid.EnableViewState = true;
            grid.AutoGenerateColumns = false;
            grid.AllowSorting = true;
            grid.AllowPaging = true;
            grid.AllowFilteringByColumn = false;
            grid.GridLines = GridLines.None;
            grid.Width = Unit.Percentage(100);
            grid.Height = Unit.Percentage(100);
            grid.HeaderStyle.Width = Unit.Pixel(150);
            grid.AllowMultiRowSelection = true;
            grid.MasterTableView.PagerStyle.Mode = GridPagerMode.NextPrevNumericAndAdvanced;
            grid.ClientSettings.EnableRowHoverStyle = true;
            grid.ClientSettings.Selecting.AllowRowSelect = true;
            grid.ClientSettings.Scrolling.AllowScroll = true;
            grid.ClientSettings.Scrolling.UseStaticHeaders = true;
            grid.ClientSettings.Scrolling.SaveScrollPosition = true;
            grid.ClientSettings.Resizing.AllowColumnResize = true;
            grid.ClientSettings.Resizing.ClipCellContentOnResize = false;
            grid.ClientSettings.Resizing.EnableRealTimeResize = true;
            grid.ClientSettings.Resizing.ResizeGridOnColumnResize = true;
            grid.MasterTableView.DataKeyNames = new string[] { "E_ID" };
            grid.MasterTableView.OverrideDataSourceControlSorting = true;
            grid.PagerStyle.AlwaysVisible = true;
            if (!IsPostBack)
            {
                grid.MasterTableView.PageSize = 15;
            }
            grid.GroupingSettings.CaseSensitive = false;
            grid.MasterTableView.PagerStyle.Width = 1000;
            grid.MasterTableView.OverrideDataSourceControlSorting = true;
            grid.MasterTableView.EnableColumnsViewState = false;
            grid.AllowFilteringByColumn = true;
 
            grid.AllowMultiRowSelection = this.EnableMultiRowSelect;
            grid.EnableMultiPageSelect = true;
 
        }
 
        private void setGridEvents(RadGrid grid)
        {
            grid.ItemDataBound += new GridItemEventHandler(rgTreeList_ItemDataBound);
            grid.NeedDataSource += new GridNeedDataSourceEventHandler(rgTreeList_NeedDataSource);
        }

I used the article you mentioned for the creation of that grid.

Best regards
Ferdinand
0
Iana Tsolova
Telerik team
answered on 05 May 2011, 02:57 PM
Hi Ferdinand,

Can I check the method for creating the grid columns as well?

All the best,
Iana
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Dominik Gierse
Top achievements
Rank 1
answered on 06 May 2011, 08:21 AM
I have to admit that there is some stuff coming out of our so called "KanioDataModel". You can consider most of that as simple strings.
Here you are:
private void createGridColumns(KanioDataSet ds)
        {
            KanioDataModel dm = KanioDataModel.Instance;
            this.rgTreeList.Columns.Clear();
 
            if (this.ShowEditField && Request[this.hfSelectedTreeItem.UniqueID] != trashValue)
            {
                DynamicGrid.AddEditButtonFieldToGridView(this.rgTreeList, true, false, false, this.IsComponentStorage);
            }
            else
            {
                DynamicGrid.AddEditButtonFieldToGridView(this.rgTreeList, true, false, true, this.IsComponentStorage);
            }
 
            // If details enabled by tooltip, set tooltip here to true
            DynamicGrid.AddNameIconFieldToGridView(null, "E_NAME", dm.GetDatatype(13).DatatypeFields["E_NAME"].CommonName,
                this.rgTreeList, this.Server);
 
            // Iterate all columns in the fetched DataSet
            foreach (DataColumn col in ds.Tables[0].Columns)
            {
                if (col.ColumnName != "E_NAME" && col.ColumnName != "E_ID")
                {
                    if (col.ColumnName == "M_ID" || col.ColumnName == "S_ID" || col.ColumnName == "DBO_ID")
                    {
                        DynamicGrid.AddGivenIdField(dm.GetDatatype(13).DatatypeFields[col.ColumnName], this.rgTreeList);
                    }
                    else if (col.ColumnName.Contains("E_INFO"))
                    {
                        DynamicGrid.AddDataValueFieldsToGridView(this.rgTreeList,
                            GetLocalResourceObject("captionLeftDataValueField").ToString(),
                            GetLocalResourceObject("captionRightDataValueField").ToString(), 1);
                    }
                    else if (!col.Caption.IsNullOrEmpty())
                    {
                        DynamicGrid.AddBoundFieldToGridView(col.ColumnName, col.Caption, this.rgTreeList);
                    }
                }
            }
        }


As an example for adding a grid column with the static DynamicGrid class:
/// <summary>
        /// Adds a standard BoundField to the GridView.
        /// </summary>
        /// <param name="fieldName">The name of the DataField that shall be used.</param>
        /// <param name="headerText">The text of the header.</param>
        /// <param name="grid">The Grid where the column shall be added.</param>
        public static void AddBoundFieldToGridView(string fieldName, string headerText, RadGrid grid)
        {
            AddBoundFieldToGridView(fieldName, headerText, grid, null);
        }
 
        /// <summary>
        /// Adds a standard BoundField to the GridView.
        /// </summary>
        /// <param name="fieldName">The name of the DataField that shall be used.</param>
        /// <param name="headerText">The text of the header.</param>
        /// <param name="grid">The Grid where the column shall be added.</param>
        /// <param name="width">The width of the column.</param>
        public static void AddBoundFieldToGridView(string fieldName, string headerText, RadGrid grid, int? width)
        {
            GridBoundColumn bc = new GridBoundColumn()
            {
                HeaderText = headerText,
                DataField = fieldName
            };
            bc.SortExpression = fieldName.Trim();
            bc.AllowSorting = true;
            bc.Resizable = true;
            bc.UniqueName = fieldName;
            if (width != null)
            {
                bc.HeaderStyle.Width = width.Value;
            }
            grid.Columns.Add(bc);
        }

Hope that helps you.
Best regards
0
Iana Tsolova
Telerik team
answered on 06 May 2011, 10:27 AM
Hi Uwe,

I checked the code for adding the grid columns and it looks fine.
Can you try enabling the MasterTableView columns ViewState and remove the like for clearing the columns on postback?
Let me know how it goes.

Kind regards,
Iana
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Ferdinand
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Ferdinand
Top achievements
Rank 1
Dominik Gierse
Top achievements
Rank 1
Share this question
or