Skip to content

Infragistics Community Forum / Web / Ultimate UI for ASP.NET Web Forms / Keeping on the same page when I refresh a grid

Keeping on the same page when I refresh a grid

New Discussion
Monroe
Monroe asked on Feb 29, 2012 11:30 PM

So I have a grid with 10 pages.  I am on page 5.  I refresh the grid because my actions might have caused a number of rows to disappear.  When I get the data and rebind, how do I go the the last page I had selected?  I want the grid to be on page 5 after the refreshing of the data.

Sign In to post a reply

Replies

  • 0
    Monroe
    Monroe answered on Feb 24, 2012 7:43 PM

    Ah…  Not as easy as it first looks.  I looked at a couple of other post and can get the current page number.  I do it with a hidden control on the client.  Now I need to set the page index.    I tried on a test button on the form that sets the DataSource and I call  DataBind().  I then try to set the pagIndex

    .Behaviors.Paging.PageIndex

    this nas no effect.  Where should I do this?

  • 0
    Hristo
    Hristo answered on Feb 27, 2012 9:32 AM

    Hello mland,

    you should be able to change page index on a button click. What is your datasource?

  • 0
    Monroe
    Monroe answered on Feb 27, 2012 4:39 PM

    So here is my test project.  On the button I have:

    WebHierarchicalDataGrid1.Behaviors.Paging.PageIndex = 2;

    I would have thought this would work but…         Any suggestions?

     

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Web;

    using System.Web.UI;

    using System.Web.UI.WebControls;

    using Infragistics.Web.UI.GridControls;

    using TotalCare.Enterprise.Common.ZeroClient;

     

    namespace TotalCare.Enterprise.ZeroClient.RequestFacility.secure.Manager.Request

    {

        public class Parent

        {

            public Parent()

            {

                Description_l = string.Empty;

                Id_l = 0;

            }

     

            public Parent(int id, string desc)

            {

                Description_l = desc;

                Id_l = id;

            }

     

            private string Description_l;

     

            public string Description

            {

                get { return Description_l; }

                set { Description_l = value; }

            }

     

            private int Id_l;

     

            public int ID

            {

                get { return Id_l; }

                set { Id_l = value; }

            }

     

        }

     

     

        public partial class _TestForm : TotalCare.Enterprise.ZeroClient.RequestFacility.common.tctBaseForm

        {

     

            protected override void OnInit(EventArgs e)

            {

                if (DesignMode)

                    return;

                base.OnInit(e);

                if (Session["Test"] == null)

                {

                    Session["Test"] = CreateData();                 

                }

     

                WebHierarchicalDataGrid1.DataSource = Session["Test"];

            }

     

            protected void Page_Load(object sender, EventArgs e)

            {

                if (Page.IsPostBack == false)

                {               

                    WebHierarchicalDataGrid1.DataBind();

                }    

            }

     

            public List<Parent> CreateData()

            {

                List<Parent> xx = new List<Parent>();

                for (int x = 0;

                          x < 90;

                          x++)

                {                

                    Parent curParent = new Parent(x, "Desc" + Convert.ToString(x));

                    xx.Add(curParent);

                }

                return xx;

            }

     

            protected void Button1_Click1(object sender, EventArgs e)

            {

                WebHierarchicalDataGrid1.Behaviors.Paging.PageIndex = 2;

            }

        }

    }

     

     

    <body>

        <form id="theForm" runat="server">

        <asp:ScriptManager ID="ScriptManager2" EnablePartialRendering="true" runat="server">

        </asp:ScriptManager>

        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click1" Text="Button" />

        <ig:WebHierarchicalDataGrid ID="WebHierarchicalDataGrid1" runat="server" AutoGenerateBands="false"

            AutoGenerateColumns="False" DataKeyFields="ID" Width="300px" Height="350px" InitialDataBindDepth="0"

            InitialExpandDepth="0">

            <Columns>

                <ig:BoundDataField DataFieldName="ID" Width="120px" Key="ID">

                    <Header Text="id_parent" />

                    <Header Text="id_parent" />

                </ig:BoundDataField>

                <ig:BoundDataField DataFieldName="Description" Width="120px" Key="Description">

                    <Header Text="desc_parent" />

                    <Header Text="desc_parent" />

                </ig:BoundDataField>

            </Columns>

            <Behaviors>

                <ig:Paging PagerAppearance="Bottom" QuickPages="5" PageSize="15" Enabled="true">

                </ig:Paging>

            </Behaviors>

        </ig:WebHierarchicalDataGrid>

        </form>

    </body>

  • 0
    Monroe
    Monroe answered on Feb 28, 2012 4:29 PM

    Any thoughts on the code I posted

  • 0
    Hristo
    Hristo answered on Feb 29, 2012 9:22 AM

    Hello mland,

    try with this:

        protected void Button1_Click1(object sender, EventArgs e)
        {
            WebHierarchicalDataGrid1.GridView.Behaviors.Paging.PageIndex = 2;
        }
    
  • 0
    Monroe
    Monroe answered on Feb 29, 2012 11:30 PM

    So that works great on a button click.  I tried to move it into Page_Load event. I am trying to set the page if it is a postback

               if (!IsPostBack)

                {                

                    this.RequestGrid.DataBind();

                    
    WebHierarchicalDataGrid1.GridView.Behaviors.Paging.PageIndex = 2;

                }

    On my demo grid this worked great.

    On my real grid I got an error, I turned off tracing and it worked.  Seems a little odd.

    Multiple controls with the same ID 'grdOffRequests:_ctl0:it1_0' were
    found. Trace requires that controls have unique IDs.

    Description:
    An unhandled exception occurred during the execution of the current web
    request. Please review the stack trace for more information about the error and
    where it originated in the code.

    Exception Details:
    System.Web.HttpException: Multiple controls with the same ID
    'grdOffRequests:_ctl0:it1_0' were found. Trace requires that controls have
    unique IDs.

    Source Error:

    An unhandled exception was generated during the execution of the
    current web request. Information regarding the origin and location of the
    exception can be identified using the exception stack trace below.

    Stack Trace:

    [HttpException (0x80004005): Multiple controls with the same ID 'grdOffRequests:_ctl0:it1_0' were found. Trace requires that controls have unique IDs.]
       System.Web.TraceContext.AddNewControl(String id, String parentId, String type, Int32 viewStateSize, Int32 controlStateSize) +525
       System.Web.UI.Control.BuildProfileTree(String parentId, Boolean calcViewState) +287
       System.Web.UI.Control.BuildProfileTree(String parentId, Boolean calcViewState) +353
       System.Web.UI.Control.BuildProfileTree(String parentId, Boolean calcViewState) +353
       System.Web.UI.Control.BuildProfileTree(String parentId, Boolean calcViewState) +353
       System.Web.UI.Control.BuildProfileTree(String parentId, Boolean calcViewState) +353
       System.Web.UI.Control.BuildProfileTree(String parentId, Boolean calcViewState) +353
       System.Web.UI.Page.BuildPageProfileTree(Boolean enableViewState) +39
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6585
    

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Monroe
Favorites
0
Replies
7
Created On
Feb 29, 2012
Last Post
14 years, 7 months ago

Suggested Discussions

Created by

Created on

Feb 29, 2012 11:30 PM

Last activity on

Feb 26, 2026 7:14 PM