Custom paging in gridview


Posted Date:     Total Responses: 0    Posted By: Mrs. Meetu Choudhary Nanda   Member Level: Gold   Points/Cash: 100   


This is a sample of customized Paging the concept implements the logic used in Google for paging the page numbers increases and decreases as in Google.. I have seen that logic and tires to implement it some how i succeeded and now i am sharing it with you all..

in this i have used a menu bar for the customized paging in the pager of a grid view....

the piece of code for the .cs file is as follows and for .aspx files and .cs files please go through the attachments..


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{

binding();
}
}
private void binding()
{
DataTable tblData = new DataTable();
DataColumn col1 = new DataColumn("Data1");
tblData.Columns.Add(col1);

for (int i = 1; i <= 1500; i++)
{
DataRow dr = tblData.NewRow();
dr["Data1"] = i;
tblData.Rows.Add(dr);
}
GridView1.DataSource = tblData;
GridView1.DataBind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Pager)
{
Menu pgmenu =(Menu) e.Row.FindControl("Menu1");
int startno, endno;
int selectedpgeno = -1;
if (ViewState["selectedpgno"] == null)
{
startno = 1;
endno = startno + 9;
}
else
{
selectedpgeno = Convert.ToInt32(ViewState["selectedpgno"]);
if ((selectedpgeno - 10) <= 0)
{
startno = 1;
endno = selectedpgeno + 9;
}
else
{
startno = selectedpgeno - 10;
endno = selectedpgeno + 9;
}
}

for (int i = startno; i <= endno; i++)
{
pgmenu.Items.Add(new MenuItem(i.ToString(), (i - 1).ToString()));
}
}
}
protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
{
ViewState.Add("selectedpgno", e.Item.Text);
GridView1.PageIndex = Convert.ToInt32(e.Item.Value);
binding();
}
protected void Navigate(object sender, CommandEventArgs e)
{
if (e.CommandName == "Next")
{
ViewState.Add("selectedpgno", GridView1.PageIndex + 1);
GridView1.PageIndex = Convert.ToInt32(GridView1.PageIndex + 1);
binding();
}
}
}


Attachments

  • Paging (540-16241-Pagin.zip)

  • Project Feedbacks

    Author: Member Level: BronzeRevenue Score: 1 out of 5
    thank you very much


    Author: Member Level: BronzeRevenue Score: 1 out of 5
    its very help to me


    Author: Member Level: BronzeRevenue Score: 1 out of 5
    good...............


    Author: Member Level: BronzeRevenue Score: 3 out of 53 out of 53 out of 5
    Thanks to posting this great code
    It is working properly but

    is it possiable that whatever page no I have clicked can be show as selected ?
    By which user can esaily know that which page I am currently working

    I unable to selcted node in the menu controle



    Author: Member Level: GoldRevenue Score: 1 out of 5
    Great work!
    Its a really helpful to those who are facing such kind of problems.

    Keep it up!


    Author: Member Level: GoldRevenue Score: 1 out of 5
    Nice work Meetu,


    Keep going......


    Author: Member Level: GoldRevenue Score: 1 out of 5
    its really good


    Author: Member Level: SilverRevenue Score: 1 out of 5
    Nice Coding.



    Author: Member Level: GoldRevenue Score: 2 out of 52 out of 5
    code that u send not working properly.

    i chnage some code loop only upto 150.

    it showing me more than 15 link.

    find attached screnshot.


    screenshot.doc
    Post Feedback
    You must Sign In to post a feedback.
    Next Project: Three Layer Architecture.
    Previous Project: Excel Operation (Update/Select/Insert)

    Return to Project Index

    Post New Project


    Related Projects


    Top Contributors
    TodayLast 7 Daysmore...

    Awards & Gifts
     
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India