0

I have a Tab Control that contains a ListView, there are three Tabs, each tab contains the same ListView but the Data Source is changed whenever the tab chagnes.

Lets say there are 3 Tabs: Tab1: Customers Tab2: Items Tab3: Orders

The problem comes when I use a DataPager. (Previous 1 2 3 4 5 6 ... Next) The DataPager uses a QueryString:

<asp:DataPager runat="server" ID="DataPager1" PagedControlID="ListView1" PageSize="5"     QueryStringField="page"  OnPreRender="Pager_PreRender" >
    <Fields>
        <asp:NextPreviousPagerField ButtonType="Button" PreviousPageText="Previous" />
        <asp:NumericPagerField ButtonType="Link" ButtonCount="10" />
        <asp:NextPreviousPagerField ButtonType="Button" NextPageText="Next" />
    </Fields>
</asp:DataPager>

This produces the following URL:

http:// localhost /MyProject/view/Customers?page=1

Lets say I'm in Tab3: Orders, if I navigate to the next Page a postback occurs and Tab1: Customers is displayed instead and that is because the URL indicates view/Customers?page=1 Is there anyway to achieve paging without using the QueryString?

Here is where I use the QueryString:

    protected void Pager_PreRender(object sender, EventArgs e)
    {
        int CurrentPage = 0;
        Int32.TryParse(Request.QueryString["page"], out CurrentPage);
        CurrentPage = CurrentPage.Equals(0) ? 1 : CurrentPage;

        HyperLink PreviousLink = DataPager1.Controls[0].Controls[0] as HyperLink;
        HyperLink NextLink = DataPager1.Controls[2].Controls[0] as HyperLink;
        if (PreviousLink != null)
        {
            if (CurrentPage.Equals(1))
            {
                PreviousLink.Visible = false;
            }
            else if (CurrentPage > 1)
            {
                PreviousLink.Visible = true;
            }
        }
        if (NextLink != null)
        {
            if ((CurrentPage * DataPager1.PageSize) >= DataPager1.TotalRowCount)
            {
                NextLink.Visible = false;
            }
            else
            {
                NextLink.Visible = true;
            }
        }
    }
Eric Bergman
  • 1,453
  • 11
  • 46
  • 84

1 Answers1

0

You could use a PagingDataSet and use a HiddenField to store the page index. Just explained in another answer...

Custom datatable with paging

Make sense?

Community
  • 1
  • 1
CoderMarkus
  • 1,118
  • 1
  • 10
  • 24
  • Thanks for the reply but no it still doesn't make any sense, I did not understand what was said in that post. – Eric Bergman Aug 16 '12 at 04:53
  • What about using what you have, but instead of using hyperlinks and redirecting each time a page is changed, you use linkbuttons and postback to move across pages. You could use a hiddenfield to hold the page index of each tab. – CoderMarkus Aug 16 '12 at 05:49