为了账号安全,请及时绑定邮箱和手机立即绑定

DataGrid 不会显示下一页的数据

DataGrid 不会显示下一页的数据

C#
红糖糍粑 2021-06-11 14:12:54
无论我单击哪个页面,我的 DataGrid 都会显示来自第一页的数据,我已经搜索了解决方案,但没有任何效果。我已经把BindGrid对!IsPostBack和重新绑定在网格grid1_PageIndexChanging。这是我的代码:protected void Page_Load(object sender, EventArgs e){    if (!IsPostBack)    {        BindGrid();    }}private int GetNumItems(){    SqlConnection con = new SqlConnection();    con.ConnectionString = gc.GetWebConfigConnectionStringAIS();    con.Open();    string query = "SELECT COUNT(*) FROM dbo.TestingLatihan";    SqlCommand cmd = new SqlCommand(query, con);    Int32 totalRow = (Int32)cmd.ExecuteScalar();    con.Close();    return totalRow;}protected void grid1_PageIndexChanging(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e){    grid1.CurrentPageIndex = e.NewPageIndex;    BindGrid();}private void BindGrid() {    grid1.VirtualItemCount = GetNumItems();    grid1.PageIndexChanged += new DataGridPageChangedEventHandler(grid1_PageIndexChanging);    SqlConnection con = new SqlConnection();    con.ConnectionString = gc.GetWebConfigConnectionStringAIS();    con.Open();    string query = "SELECT * FROM dbo.TestingLatihan";    SqlCommand cmd = new SqlCommand(query, con);    SqlDataAdapter myAdapter = new SqlDataAdapter(cmd);    DataTable dt = new DataTable();    myAdapter.Fill(dt);    grid1.DataSource = dt;    grid1.DataBind();    con.Close();  }和我的 .aspx<asp:DataGrid ID="grid1" runat="server" AutoGenerateColumns="False"CellPadding="4" ForeColor="#333333" Width="100%" OnItemCommand="dtgItemCommand" AllowPaging="True" PageSize="5" AllowCustomPaging="True" OnPageIndexChanged="grid1_PageIndexChanging" EnableViewState="true">   <AlternatingItemStyle CssClass="tdgenap" />   <ItemStyle CssClass="tdganjil" HorizontalAlign="Center" />      <HeaderStyle HorizontalAlign="Center" Height="30px" CssClass="tdjudul"></HeaderStyle>          <Columns>            
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 224 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信