asp.net - Gridview 中的分页不起作用 第二页数据未显示数据?

标签 asp.net gridview paging

我的网格 View

<div style="margin-left: 280px">
   <asp:GridView ID="exportGrdVw" runat="server" BackColor="White"  
        AllowPaging="True" PageSize="3" 
        OnPageIndexChanging="exportGrdVw_PageIndexChanging" 
        onpageindexchanged="exportGrdVw_PageIndexChanged">
   </asp:GridView>
</div>

我的代码
SqlConnection con = new SqlConnection("server=acer-Pc\\Sql;database=MYDB;trusted_connection=yes");  
//DataSet ds = new DataSet();
DataTable table = new DataTable();    
protected void Page_Load(object sender, EventArgs e)
{        
    if (!IsPostBack)
    {
        SqlDataAdapter da = new SqlDataAdapter("select customername,contactno,address from employee ", con);
        da.Fill(table);
        BindEmployee();
    }
 }
 public void BindEmployee()
 {
    exportGrdVw.DataSource = table;
    exportGrdVw.DataBind();
 }
 protected void exportGrdVw_PageIndexChanging(object sender, GridViewPageEventArgs e)
 {
    exportGrdVw.PageIndex = e.NewPageIndex;
    BindEmployee();
 }

问题是 gridview 正在显示,但是当我单击第 2 页时。第 2 页数据未显示(空白)。请帮我解决这个问题。
查看代码是否正确

最佳答案

使用如下

SqlConnection con = new SqlConnection("server=acer-Pc\\Sql;database=MYDB;trusted_connection=yes");
//DataSet ds = new DataSet();
DataTable table = new DataTable();    
protected void Page_Load(object sender, EventArgs e)
{        
   if (!IsPostBack)
   {              
       BindEmployee();
   }
}
public void BindEmployee()
{
    SqlDataAdapter da = new SqlDataAdapter("select customername,contactno,address from employee ", con);
    da.Fill(table);
    exportGrdVw.DataSource = table;
    exportGrdVw.DataBind();
}
protected void exportGrdVw_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    exportGrdVw.PageIndex = e.NewPageIndex;
    BindEmployee();
}

关于asp.net - Gridview 中的分页不起作用 第二页数据未显示数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15666136/

相关文章:

c# - 将复选框绑定(bind)到数据库中的位字段 (AJAX)

php - php mysql 中的分页

java - 使用 Objectify 获取光标而不迭代项目

c# - ASP.NET MVC Core 如何获取应用程序支持的文化列表

asp.net - 如何将default.aspx设置为Visual Studio调试器的默认启动点?

c# - ASP.NET MVC自定义错误处理Application_Error Global.asax?

c# - 如何设置gridview边框的样式?

c# - NServiceBus升级后"Unable to find assembly"

android - picasso 图书馆和 GridView 图像

php - 搜索高级 php/mysql 分页脚本