Click here to Skip to main content
15,889,655 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
Hi i want to appy pagination for the grid .for this iam using allow pagination property which is there in the grid .but my datatable which is binding to the data has lacs of records so when iam binding the data to the grid its taking some time to bind .hence i want to get only 100 records from the datatable to bind to the grid.for eg if i have 1000 records then i want to bring 100 records at a time but i want to show 1 to 10 numbers in the grid so when user click 2 no in the grid i want to bring from 200 to 300 pages .for this how can show numbers in the grid.

thanks in advance
Posted

C#
gridview.pageindex=e.newpageindex;

//Bind again gridview
 
Share this answer
 
v2
Hi ,
Try this

C#
    protected void Page_Load(object sender, EventArgs e)
    {
//set your grid page size  propriety 
        GridView1.PageSize = 100;
    }

  protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
//then you have to Rebind DataGrid again 
        SqlConnection con = new SqlConnection(@"Data Source=.;Initial Catalog=test;Integrated Security=True");
        string statment = "select item_code, Item_name, brand, size, section, price, Material, Qty, tax, tt  from Items ";
        SqlDataAdapter da = new SqlDataAdapter(statment, con);
        DataSet ds = new DataSet();
        da.Fill(ds);
        GridView1.DataSource = ds.Tables[0];
        GridView1.DataBind();
    }


Best Regards
M.Mitwalli
 
Share this answer
 
This problem is not just the pagination the problem is that too many records coming out from DB. try to pass start row and end row in the query and use rowcount() inside query to get only small set to records out. you will need to pass the start row and end row from the page which should show only the retrieved result in grid.

store the current start and end row in hidden fields to get next set of records or use Object data source where object keeps track of start and end row.
 
Share this answer
 
Here is my two article on gridview pagination hope that you like it


ASP.NET Extended Grid Control[^]


LINQ TO SQL GridView (Enhanced Gridview)[^]
 
Share this answer
 
v2
Hello,
As you are having huge data,go with sollution 3 once you Done.
check with this its excellent jquery plugin.


http://datatables.net/examples/basic_init/alt_pagination.html[^]
 
Share this answer
 
v2
Using custom pagination this could be done
 
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