我们的程序里面用的是DataGrid的自动分页的功能
AllowPaging=true AllowCustomPaging=false
单独查看这个页面可以实现分页的功能
但是运行程序跳转到有分页的页面时就有问题
问题是要把AllowCustomPaging=true,但改成AllowCustomPaging=true后,分页的功能又不能实现,不知道是怎么回事
有知道的请教一下我们
AllowPaging=true AllowCustomPaging=false
单独查看这个页面可以实现分页的功能
但是运行程序跳转到有分页的页面时就有问题
问题是要把AllowCustomPaging=true,但改成AllowCustomPaging=true后,分页的功能又不能实现,不知道是怎么回事
有知道的请教一下我们
{
this.DataGrid1.CurrentPageIndex = e.NewPageIndex;
this.DataGrid1.SelectedIndex = -1;
sql_conect();
}
如果你的绑定的是SqlDataReader的话,就不行。。特别是在设置了分页功能!
当 AllowPaging 设置为真并且选定的数据源不实现 ICollection 时,AllowCustomPaging 必须为真,并且 ID 为 DataGrid1 的 DataGrid 必须设置 VirtualItemCount。
事件处理程序接收 DataGridPageChangedEventArgs 对象作为参数。可以使用该参数的 NewPageIndex 属性来确定用户从 DataGrid 控件的页选择元素中所选择的页的索引。
接下来,创建包含要在单页显示的数据的数据源,然后使用 DataBind 方法将数据绑定到 DataGrid 控件。注意
因为只加载一个数据段,所以您必须将 VirtualItemCount 属性设置为 DataGrid 控件中各项的总数。这使得该控件可以确定显示 DataGrid 控件中每一项所需的总页数。只要确定了 DataGrid 控件中的总项数,通常就可以用编程的方式设置此属性。
在通过将 AllowCustomPaging 属性设置为 false 来启用分页后,DataGrid 控件假设数据源包含所有要显示的项。DataGrid 控件根据 CurrentPageIndex 属性指定的页索引以及 PageSize 属性指定的页上项的数目来计算显示的页上各项的索引。当 AllowCustomPaging 属性设置为 true 时,DataGrid 控件假设数据源只包含由 VirtualItemCount 属性确定的项。所有项(项数最多可达由 PageSize 属性指定的数目)都将显示出来。
===========以上完全摘录自msdn,示例代码自己看看======================
试着先自己找资料解决
====
~~~~ 我的Blog:http://blog.csdn.net/quou2002
SqlConnection con=DB.createConnection();
SqlDataAdapter sdr=new SqlDataAdapter();
sdr.SelectCommand=new SqlCommand("select * from sharetable",con);
DataSet dt=new DataSet();
sdr.Fill(dt,"sharetable");
this.DataGrid1.DataKeyField="id";
this.DataGrid1.DataSource=dt.Tables["sharetable"];
this.DataGrid1.DataBind();
这样绑定就应该行咯
<%@ Page Language="VB" AutoEventWireup="True" Debug="true"%>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQLClient" %>
<script runat="server">
Dim MyConnection as SQLConnection
Dim MyCommand As SQLDataAdapter Sub Page_Load(sender As Object, e As EventArgs)
MyConnection = New SqlConnection("server=localhost;Initial Catalog=pubs;uid=sa;pwd=")
If Not IsPostBack Then
BindGrid()
End If
End Sub Sub BindGrid()
Dim MyCommand As SQLDataAdapter = new SQLDataAdapter("SELECT * FROM authors", MyConnection)
Dim DS As DataSet = new DataSet()
MyCommand.Fill(DS,"min")
MyDataGrid.DataSource = DS.Tables("min").DefaultView
MyDataGrid.DataBind()
End Sub
</script>
<form runat="server">
<asp:DataGrid id="MyDataGrid"
runat="server"
AutoGenerateColumns="true"
Width="200">
<HeaderStyle BackColor="Navy"
ForeColor="White"
Font-Bold="True"
HorizontalAlign="Center"/>
<PagerStyle Mode="NextPrev"
HorizontalAlign="Right"
NextPageText="下一页"
PrevPageText="上一页"/>
</asp:DataGrid>
</form>
http://dotnet.aspx.cc/ShowDetail.aspx?id=108B1516-53CE-4357-B061-17295AF9689F
{
DataGrid1.CurrentPageIndex=e.NewPageIndex;
BindGrid();
}
这里设置没有?