web窗体上的datagrid在定义了AllowCustomPaging="True" AllowPaging="True" PageSize="5"就是不翻页?为什么呢?

booksfount 2004-02-20 12:45:01
web窗体上的datagrid在定义了AllowCustomPaging="True" AllowPaging="True" PageSize="5"。VirtualItemCount也设置了,就是不翻页?为什么呢?
我想每次仅加载当前页的数据所以让AllowCustomPaging="True"。页码出来了,但是并不翻页,按下页码,页面也重新加载,但永远停留在第一页上,请问怎么解决???谢谢!!

aspx文件如下:
<%@ Page language="c#" Codebehind="customPage.aspx.cs" AutoEventWireup="false" Inherits="asptest.customPage" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>customPage</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<asp:datagrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 40px; POSITION: absolute; TOP: 88px" runat="server"
Width="328px" Height="160px" AllowCustomPaging="True" AllowPaging="True" PageSize="5">
<PagerStyle HorizontalAlign="Right" Mode="NumericPages"></PagerStyle>
</asp:datagrid>
<asp:Label id="Label1" style="Z-INDEX: 102; LEFT: 48px; POSITION: absolute; TOP: 24px" runat="server"
Width="56px" Height="40px">pagesmemo</asp:Label></FONT></form>
</body>
</HTML>

-------------------------------------------------------------
aspx.cs内容如下:

using .......省略

namespace asptest
{

public class customPage : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.DataGrid DataGrid1;

private void Page_Load(object sender, System.EventArgs e)
{

if (!Page.IsPostBack)
{
DataGrid1.VirtualItemCount = 39;//测试用,表里就39条纪录。
greebind();
}
}
void greebind()
{
SqlConnection conn;
conn= new SqlConnection("data source=txmw2kpro;persist security info=true;uid=sa;pwd=111111;database=testdb");
conn.Open();
SqlDataAdapter sda;
sda = new SqlDataAdapter("select write_sect_no,write_sect_name from write_sect",conn);
DataSet ds=new DataSet();
sda.Fill(ds,"write_sect");
DataGrid1.DataSource =ds.Tables[0].DefaultView;
DataGrid1.DataBind();

}
#region Web 窗体设计器生成的代码//省略了.......
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
greebind(); //也重新绑定了数据
Label1.Text= DataGrid1.CurrentPageIndex.ToString();//观察currentpageindex是变化的
}
}
}

谢谢帮助!
...全文
49 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧