如何对网格应用分页 [英] how to apply pagination for the grid

查看:114
本文介绍了如何对网格应用分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为网格应用分页.为此,我使用网格中存在的允许分页属性进行分页.但是绑定到数据的我的数据表有很多记录,所以当iam将数据绑定到网格时需要一些时间来绑定.因此,我想从数据表中仅获取100条记录以绑定到网格.例如,如果我有1000条记录,那么我想一次带100条记录,但是我想在其中显示1到10个数字网格,因此,当用户单击网格中的2 no时,我希望从200到300页进入.为此,如何在网格中显示数字.

在此先感谢

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

推荐答案

gridview.pageindex=e.newpageindex;


//再次绑定gridview


//Bind again gridview



试试这个

Hi ,
Try this

    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();
    }



最好的问候
M.Mitwalli



Best Regards
M.Mitwalli


这个问题不仅是分页,而是来自数据库的太多记录.尝试在查询中传递开始行和结束行,并在查询内部使用rowcount()来获取仅一小部分记录.您将需要传递页面的开始行和结束行,该页面应仅在网格中显示检索到的结果.

将当前的起始行和结束行存储在隐藏字段中以获取下一组记录,或者使用Object数据源,其中object跟踪起始行和结束行.
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.


这篇关于如何对网格应用分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆