在c#中的gridview中进行分页 [英] Pagesorting in gridview in c#

查看:76
本文介绍了在c#中的gridview中进行分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hai,



在gridview中我设置了alloworting =true。但是在运行后如果我们点击第二页就不会显示行。我有添加了Page_indexchanging代码。下面是code.Plz帮助。



Hai,

In gridview I have set allowsorting="true".But after running if we click the 2nd page it will not displaying the rows.I have added "Page_indexchanging" code also.Below is the code.Plz help.

protected void grdEmployee_PageIndexChanging(object sender, GridViewPageEventArgs e)
   {
       grdEmployee.PageIndex = e.NewPageIndex;
       grdEmployee.DataBind();
   }










<asp:GridView ID="grdEmployee" runat="server" AutoGenerateEditButton="true" 
        AllowPaging="true" AllowSorting="true" GridLines="Horizontal"  
            AutoGenerateDeleteButton="true" onrowediting="grdEmployee_RowEditing" 
        AutoGenerateColumns="false" DataKeyNames="IncidentNumber"
            onrowupdating="grdEmployee_RowUpdating" ShowFooter="true" 
        CellPadding="3" CellSpacing="3" BorderColor="ActiveBorder"
            onrowcancelingedit="grdEmployee_RowCancelingEdit" AutoGenerateSelectButton="true" 
         onrowdeleting="grdEmployee_RowDeleting" 
            Width="1076px" onpageindexchanging="grdEmployee_PageIndexChanging"
         >
</asp:GridView>

推荐答案

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    grdEmployee.PageIndex = e.NewPageIndex;
    //rebind your gridview - GetSource(),Datasource of your GirdView
    grdEmployee.DataSource = GetSource();
    grdEmployee.DataBind();

}


嘿会员10234093

尝试再次将数据源添加到gridview然后调用数据绑定()函数
Hey Member 10234093
try to add Data Source again to gridview then call the databind() function


尝试这样: -

try like this:-
protected void GridView1_PageIndexChanging(object sender, System.Web.UI.WebControls.GridViewPageEventArgs e)
{
   
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.DataSource = dtTray; //your data source
        GridView1.DataBind();
   
}


这篇关于在c#中的gridview中进行分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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