Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Dear All,

am working on asp.net ,c#,SqlServer2005.

I have a Gridview filled with thousands of records. and also i did paging for it.

just like 1 2 3 4 5 6 7 8 9 10...........500

Now my requirement is when the user clicks on page 2.

below gridview it must show a label message "you are viewing page 2 of 100.

i need this by coding.

Please help

Thanks for ever.
Posted

1 solution

hi,
here an example i use "ProductInfo" class for GridView DataSource, "dtgView" my GridView and "lblPageInfo Label for display page information. You need to GridView AllowPaging="True" and generate OnPageIndexChanging="dtgView_PageIndexChanging" Event for paging your GridView.

then need to Bind GridView on page load code below:
C#
protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                List<productinfo> list = new ProductInfo().SelectAll4Grid();
                // Collection of Product.
                dtgView.DataSource = list; 
                dtgView.DataBind();
                lblPageInfo.Text = "you are viewing page 1 of " + dtgView.PageCount.ToString();
                // Display Page Information.
            }
        }
</productinfo>


then you need to Bind GridView on page index changing event and collect your page information code below:
C#
protected void dtgView_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            List<productinfo> list = new ProductInfo().SelectAll4Grid();
            dtgView.PageIndex = e.NewPageIndex;
            lblPageInfo.Text = "you are viewing page " + (e.NewPageIndex + 1).ToString() + " of " + dtgView.PageCount.ToString();
            // Page Index Start from 0 so we need +1
            dtgView.DataSource = list;
            dtgView.DataBind();
        }
</productinfo>


it's working on my project. try use it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900