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

RadGrid with RadFilter reverts to first load state on pagination

4 Answers 132 Views
Grid
This is a migrated thread and some comments may be shown as answers.
adam
Top achievements
Rank 1
adam asked on 12 Jul 2011, 05:15 PM
i have a radgrid which users the radfilter to filter the datasource, filter works fine but if the first page says 2 pages and i click to go to page 2 it reloads into it inital first load state with all the data. any ideas

here is my code

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ProductSearch.ascx.cs" Inherits="Controls_ProductSearch" %>
 
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" >
<AjaxSettings>
    <telerik:AjaxSetting AjaxControlID="RadGridProductsSearch">
        <UpdatedControls>                   
            <telerik:AjaxUpdatedControl ControlID="RadGridProductsSearch" LoadingPanelID="RadAjaxLoadingPanel1"></telerik:AjaxUpdatedControl>
        </UpdatedControls>
    </telerik:AjaxSetting>             
    <telerik:AjaxSetting AjaxControlID="BtnProductSearch">
        <UpdatedControls>                   
            <telerik:AjaxUpdatedControl ControlID="RadGridProductsSearch" LoadingPanelID="RadAjaxLoadingPanel1"></telerik:AjaxUpdatedControl>
        </UpdatedControls>
    </telerik:AjaxSetting>      
</AjaxSettings>   
</telerik:RadAjaxManager>
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" Transparency="20" BackColor="#ffffff" runat="server">
    <asp:Image ID="Image1" runat="server" AlternateText="Loading..." BorderWidth="0px" ImageUrl="~/Includes/images/ajax/Loading.gif" />
</telerik:RadAjaxLoadingPanel>
<fieldset>
<ol>
    <li>
        <asp:Label ID="LblCategory" runat="server" Text="Search by Category" AssociatedControlID="ComboCategoryName"></asp:Label>
        <telerik:RadComboBox ID="ComboCategoryName" runat="server" Width="240"></telerik:RadComboBox>
    </li>
    <li class="small">
    <span> or </span>
    </li>
    <li>
        <asp:Label ID="LblKeywords" runat="server" Text="by Keyword" AssociatedControlID="ComboKeyword"></asp:Label>
        <telerik:RadComboBox ID="ComboKeyword" runat="server" Width="240" Filter="Contains" MarkFirstMatch="true" ChangeTextOnKeyBoardNavigation="false"></telerik:RadComboBox>
    </li>
    <li class="submit">
        <telerik:RadButton ID="BtnProductSearch" OnClick="BtnProductSearch_Click" runat="server" Text="Submit"></telerik:RadButton>                
    </li>
</ol>   
<telerik:RadFilter ID="SearchRadFilter" runat="server" Visible="false" ShowApplyButton="true" ExpressionPreviewPosition="None" ShowLineImages="true" FilterContainerID="RadGridProductsSearch"></telerik:RadFilter>   
</fieldset
<telerik:RadGrid ID="RadGridProductsSearch" runat="server"  SkinID="products" AllowPaging="true" PagerStyle-AlwaysVisible="true" BorderWidth="0" OnNeedDataSource="ProductsSearch_NeedDataSource" OnItemDataBound="ProductsSearch_ItemDataBound" OnItemCreated="ProductsSearch_ItemCreated" AllowSorting="true" AllowFilteringByColumn="true">
<GroupingSettings CaseSensitive="false"/>
<MasterTableView AutoGenerateColumns="false"  IsFilterItemExpanded="False">
<PagerTemplate>
    <asp:Panel ID="PagerPanel" runat="server" CssClass="pager-holder">
        <div class="pager">
            <span class="pagerPrev">
                <asp:LinkButton ID="ButtonPrev" runat="server" OnClientClick="changePage('prev'); return false;" CommandName="Page" CommandArgument="Prev" Text="<" CssClass="PagerButton PrevPage" />                           
            </span>
            <asp:Panel runat="server" ID="NumericPagerPlaceHolder" CssClass="pagerNumber" />
            <span class="pagerNext">
                <asp:LinkButton ID="ButtonNext" runat="server" OnClientClick="changePage('next'); return false;" CommandName="Page" CommandArgument="Next" Text=">" CssClass="PagerButton NextPage" />
            </span>
        </div>
        <span class="pagerSize">
            <span>View</span>
            <telerik:RadComboBox ID="RadComboBox1" DataSource="<%# new object[]{10, 20, 30, 40, 50} %>" SelectedValue='<%# DataBinder.Eval(Container, "Paging.PageSize") %>' runat="server" Width="60" OnClientSelectedIndexChanged="RadComboBox1_SelectedIndexChanged"></telerik:RadComboBox>
        </span>
    </asp:Panel>
</PagerTemplate>
<PagerStyle Mode="NumericPages" PageButtonCount="10" />            
    <Columns>
        <telerik:GridTemplateColumn HeaderText="Product Name" DataField="Name" SortExpression="Name" UniqueName="Name">
            <ItemTemplate>
                <asp:HyperLink ID="ProductLink" runat="server" NavigateUrl='<%# Functions.GetUrl(DataBinder.Eval(Container, "DataItem.NodeAliasPath")) %>' Text='<%# Eval("Name") %>'></asp:HyperLink>                           
            </ItemTemplate>
        </telerik:GridTemplateColumn
        <telerik:GridTemplateColumn HeaderText="NodeParentID" Visible="false" UniqueName="NodeParentID" DataField="NodeParentID">
        <ItemTemplate>
            <asp:Label ID="NodeParentID" runat="server"></asp:Label>
        </ItemTemplate>
        </telerik:GridTemplateColumn>                   
        </Columns>                 
</MasterTableView>        
</telerik:RadGrid
 <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
<script type="text/javascript">
var tableView = null;
function pageLoad(sender, args) {
    tableView = $find("<%= RadGridProductsSearch.ClientID %>").get_masterTableView();
}
 
function RadComboBox1_SelectedIndexChanged(sender, args) {
    tableView.set_pageSize(sender.get_value());
}
 
function changePage(argument) {
    tableView.page(argument);
}
 
function RadNumericTextBox1_ValueChanged(sender, args) {
    tableView.page(sender.get_value());
}
</script>
</telerik:RadCodeBlock>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using CMS.CMSHelper;
using CMS.GlobalHelper;
using Telerik.Web.UI;
 
public partial class Controls_ProductSearch : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadCategories();
            LoadProducts();
        }
    }
 
    void LoadCategories()
    {
        DataSet ds = TreeHelper.SelectNodes(CMSContext.CurrentAliasPath + "/%", false, "adam.productCategory", null, "Name Asc", -1, true);
 
        if (!DataHelper.DataSourceIsEmpty(ds))
        {
            ComboCategoryName.DataSource = ds;
            ComboCategoryName.DataTextField = "Name";
            ComboCategoryName.DataValueField = "NodeID";
            ComboCategoryName.DataBind();
 
            ComboCategoryName.Items.Insert(0, new RadComboBoxItem("Select Category"));
        }
    }
 
    void LoadProducts()
    {
        DataSet ds = TreeHelper.SelectNodes(CMSContext.CurrentAliasPath + "/%", false, "adam.product", null, "Name Asc", -1, true);
 
        if (!DataHelper.DataSourceIsEmpty(ds))
        {
            ComboKeyword.DataSource = ds;
            ComboKeyword.DataTextField = "Name";
            ComboKeyword.DataValueField = "Name";
            ComboKeyword.DataBind();
 
            ComboKeyword.Items.Insert(0, new RadComboBoxItem("Select Category"));
        }
    }
 
    protected void ProductsSearch_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            DataRowView dr = (DataRowView)e.Item.DataItem;
 
            GridDataItem item = (GridDataItem)e.Item;
            Label nodeParentID = item.FindControl("NodeParentID") as Label;
 
            CMS.TreeEngine.TreeNode node = TreeHelper.SelectSingleNode((int)DataHelper.GetDataRowViewValue(dr, "NodeParentId"));
            if (node != null)
            {
                nodeParentID.Text = node.DocumentName;
            }
        }
    }
 
    protected void ProductsSearch_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
    {
        DataSet ds = TreeHelper.SelectNodes(CMSContext.CurrentAliasPath + "/%", false, "adam.product", null, "Name Asc", -1, true);
 
        if (!DataHelper.DataSourceIsEmpty(ds))
        {
 
            RadGridProductsSearch.DataSource = ds;
        }
        else
        {
            RadGridProductsSearch.Visible = false;
        }
    }
 
    protected void ProductsSearch_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
        if (e.Item is GridPagerItem)
        {
            GridPagerItem gridPager = e.Item as GridPagerItem;
            Control numericPagerControl = gridPager.GetNumericPager();
            numericPagerControl.ID = "";
 
            Control placeHolder = gridPager.FindControl("NumericPagerPlaceHolder");
            placeHolder.Controls.Add(numericPagerControl);
        }
    }
 
    protected void BtnProductSearch_Click(object sender, EventArgs e)
    {
        SearchRadFilter.RootGroup.Expressions.Clear();
 
        if (ComboCategoryName.SelectedIndex != 0)
        {
            RadFilterGroupExpression category = new RadFilterGroupExpression();
            category.GroupOperation = RadFilterGroupOperation.And;
            RadFilterEqualToFilterExpression<int> expr = new RadFilterEqualToFilterExpression<int>("NodeParentID");
            expr.Value = Convert.ToInt32(ComboCategoryName.SelectedValue);
            SearchRadFilter.RootGroup.AddExpression(category);
            category.AddExpression(expr);
        }
 
        if (ComboKeyword.SelectedIndex != 0)
        {
            RadFilterGroupExpression product = new RadFilterGroupExpression();
            product.GroupOperation = RadFilterGroupOperation.And;
            RadFilterEqualToFilterExpression<string> expr2 = new RadFilterEqualToFilterExpression<string>("Name");
            expr2.Value = ComboKeyword.SelectedValue;
            SearchRadFilter.RootGroup.AddExpression(product);
            product.AddExpression(expr2);
        }
 
        SearchRadFilter.FireApplyCommand();
    }
}

4 Answers, 1 is accepted

Sort by
0
adam
Top achievements
Rank 1
answered on 13 Jul 2011, 09:07 AM
anyone?
0
Iana Tsolova
Telerik team
answered on 15 Jul 2011, 11:03 AM
Hello Adam,

Can you try disabling ajax and see if it makes any difference? If it works without ajax, then try modifying the ajax settings as below:
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" >
<AjaxSettings>
    <telerik:AjaxSetting AjaxControlID="RadGridProductsSearch">
        <UpdatedControls>                   
            <telerik:AjaxUpdatedControl ControlID="RadGridProductsSearch" LoadingPanelID="RadAjaxLoadingPanel1"></telerik:AjaxUpdatedControl>
        </UpdatedControls>
    </telerik:AjaxSetting>             
    <telerik:AjaxSetting AjaxControlID="BtnProductSearch">
        <UpdatedControls>                   
            <telerik:AjaxUpdatedControl ControlID="RadGridProductsSearch" LoadingPanelID="RadAjaxLoadingPanel1"></telerik:AjaxUpdatedControl>
            <telerik:AjaxUpdatedControl ControlID="SearchRadFilter" LoadingPanelID="RadAjaxLoadingPanel1"></telerik:AjaxUpdatedControl>
        </UpdatedControls>
    </telerik:AjaxSetting>      
</AjaxSettings>   
</telerik:RadAjaxManager>



Let me know how it goes.

Regards,
Iana
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
adam
Top achievements
Rank 1
answered on 15 Jul 2011, 11:18 AM
Hi Iana 

i have solved the issue, it was caused by Kentico portal page life cycle.

thanks anyway
0
Paul
Top achievements
Rank 1
answered on 12 Apr 2012, 09:29 AM
Can you explain how you resolved the issue? I having problems using the RadGrid control within Kentico portal pages.

Thanks.
Tags
Grid
Asked by
adam
Top achievements
Rank 1
Answers by
adam
Top achievements
Rank 1
Iana Tsolova
Telerik team
Paul
Top achievements
Rank 1
Share this question
or