如何处理DataGrid中的PageIndexChanging事件? [英] how to handle the PageIndexChanging event in the DataGrid ?

查看:161
本文介绍了如何处理DataGrid中的PageIndexChanging事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在设置了AllowPaging值= true

后,在DataGrid中处理 PageIndexChanging 事件?

解决方案

Mahendra.p25上面提供的解决方案是好的,只要数据不大。



更大的记录(可能是2000年)此方法可能会降低速度方面的性能。因此,如果您要在DataGrid中定位更大的记录,请使用自定义分页。



自定义分页是方法其中记录是根据需要从数据库填充的。让我们考虑您的页面大小为20.因此,在第一页中,只需要20条记录。如果在第二页上使用点击,则应该在那时加载该页面的数据,而不是在第-1页。请在下面找到自定义分页实现的链接。



我还建议您实现分页的自定义控制,以便您可以在任何地方重复使用适用的以及其他应用程序。



参考链接-1 [ ^ ]



参考链接-2 [ ^ ]


试试这个



  //   OnPageIndexChanging =GridView1_PageIndexChanging 
protected void GridView1_PageIndexChanging( object sender,GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
BindGrid();
}


Quote:

// OnPageIndexChanging = GridView1_PageIndexChanging

protected void GridView1_PageIndexChanging(object sender,GridViewPageEventArgs e)

{

GridView1.PageIndex = e.NewPageIndex;

Gridview1.Databind();

}







 受保护的  Sub  TypesGrid_PageIndexChanging(sender  As  对象,e 作为 GridViewPageEventArgs)句柄 TypesGrid.PageIndexChanging 
TypesGrid.PageIndex = e.NewPageIndex
TypesGrid.DataBind()
End


How to handle the PageIndexChanging event in the DataGrid ??
after setting it's AllowPaging value = true

解决方案

Above provided solution by Mahendra.p25 is good as far as data are not larger.

For the larger records(may be 2000 up), this method may degrade the performance in terms of speed.So if you are targeting larger records in the DataGrid, go with custom paging.

Custom paging is method in which records are populated from database on demand. Let's consider you have page size of 20. So in the first page, only 20 records are needed. If use clicks on 2nd page, then data of that page should be loaded at that time and not at the page -1. Please find the links below for the custom paging implementation.

I would also suggest you to implement a custom control of the paging, so that you can re-use anywhere in the applicable and also in other applications as well.

Reference Link-1[^]

Reference Link-2[^]


try this

//OnPageIndexChanging="GridView1_PageIndexChanging"
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            BindGrid();
        }


Quote:

//OnPageIndexChanging="GridView1_PageIndexChanging"
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
Gridview1.Databind();
}




Protected Sub TypesGrid_PageIndexChanging(sender As Object, e As GridViewPageEventArgs) Handles TypesGrid.PageIndexChanging
       TypesGrid.PageIndex = e.NewPageIndex
       TypesGrid.DataBind()
   End Sub


这篇关于如何处理DataGrid中的PageIndexChanging事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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