我用AllowCustomPaging="True"方法,实际datagrid分页,为什么不行,求完整解决方案!
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="Articlelist.aspx.vb" Inherits="winjiasc.Articlelist"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Articlelist</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" 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="ItemsGrid" runat="server" AutoGenerateColumns="False" AllowPaging="True" BorderColor="Black"
borderwidth="1px" cellpadding="3" OnPageIndexChanged="Grid_Change" PageSize="15" AllowCustomPaging="True">
<Columns>
<asp:BoundColumn DataField="Articleid" HeaderText="编号">
<HeaderStyle Wrap="False" Width="5%"></HeaderStyle>
<ItemStyle Wrap="False"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="title" HeaderText="标题">
<HeaderStyle Wrap="False" Width="5%"></HeaderStyle>
<ItemStyle Wrap="False"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="UpdateTime" HeaderText="更新时间">
<HeaderStyle Wrap="False" Width="5%"></HeaderStyle>
<ItemStyle Wrap="False"></ItemStyle>
</asp:BoundColumn>
</Columns>
<PagerStyle NextPageText="下一页" PrevPageText="上一页"></PagerStyle>
</asp:DataGrid></FONT>
<asp:CheckBox id="CheckBox1" Runat="server" Text="显示导航" AutoPostBack="true"></asp:CheckBox></form>
</body>
</HTML>
Imports System.Data
Imports System.Data.SqlClient
Public Class Articlelist
Inherits System.Web.UI.Page
#Region " Web 窗体设计器生成的代码 "
'该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents CheckBox1 As System.Web.UI.WebControls.CheckBox
'注意: 以下占位符声明是 Web 窗体设计器所必需的。
'不要删除或移动它。
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub
#End Region
Dim start_index As Integer
Dim sqlDataSet As New DataSet
Dim sqlDataAdapter As New sqlDataAdapter '执行对数据库进行操作的命令。
Dim sqlconnection As New sqlconnection '数据库接口。
Dim sqlConString As New conn '数据库链接的代码。
Dim sqlSelectCommand As String '执行查询命令的对象
Protected WithEvents ItemsGrid As System.Web.UI.WebControls.DataGrid
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If CheckBox1.Checked Then
ItemsGrid.PagerStyle.Mode = ItemsGrid.PagerStyle.Mode.NumericPages
Else
ItemsGrid.PagerStyle.Mode = ItemsGrid.PagerStyle.Mode.NextPrev
End If
If Not IsPostBack Then
start_index = 0
' ItemsGrid.VirtualItemCount = 100
BindGrid()
End If
End Sub
Sub BindGrid()
sqlconnection.ConnectionString = sqlConString.SQLConstr
sqlconnection.Open()
sqlSelectCommand = "SELECT Articleid,title,UpdateTime FROM Article ORDER BY Articleid DESC"
Dim sqlDataCommand As New SqlCommand(sqlSelectCommand, sqlconnection)
sqlDataAdapter.SelectCommand = sqlDataCommand
sqlDataAdapter.Fill(sqlDataSet, "Tarticle")
ItemsGrid.DataSource = sqlDataSet.Tables("Tarticle")
sqlconnection.Close()
ItemsGrid.DataBind()
End Sub
Sub Grid_Change(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles ItemsGrid.PageIndexChanged
ItemsGrid.CurrentPageIndex = e.NewPageIndex
start_index = ItemsGrid.CurrentPageIndex * ItemsGrid.PageSize
BindGrid()
End Sub
End Class
为什么不能翻页?
还有就AllowCustomPaging="True"谈谈分页的问题,我有一个表中300万条记录,而且基本每天在增加,如果分页,我该如何做,希望帮忙!
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Articlelist</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" 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="ItemsGrid" runat="server" AutoGenerateColumns="False" AllowPaging="True" BorderColor="Black"
borderwidth="1px" cellpadding="3" OnPageIndexChanged="Grid_Change" PageSize="15" AllowCustomPaging="True">
<Columns>
<asp:BoundColumn DataField="Articleid" HeaderText="编号">
<HeaderStyle Wrap="False" Width="5%"></HeaderStyle>
<ItemStyle Wrap="False"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="title" HeaderText="标题">
<HeaderStyle Wrap="False" Width="5%"></HeaderStyle>
<ItemStyle Wrap="False"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="UpdateTime" HeaderText="更新时间">
<HeaderStyle Wrap="False" Width="5%"></HeaderStyle>
<ItemStyle Wrap="False"></ItemStyle>
</asp:BoundColumn>
</Columns>
<PagerStyle NextPageText="下一页" PrevPageText="上一页"></PagerStyle>
</asp:DataGrid></FONT>
<asp:CheckBox id="CheckBox1" Runat="server" Text="显示导航" AutoPostBack="true"></asp:CheckBox></form>
</body>
</HTML>
Imports System.Data
Imports System.Data.SqlClient
Public Class Articlelist
Inherits System.Web.UI.Page
#Region " Web 窗体设计器生成的代码 "
'该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents CheckBox1 As System.Web.UI.WebControls.CheckBox
'注意: 以下占位符声明是 Web 窗体设计器所必需的。
'不要删除或移动它。
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub
#End Region
Dim start_index As Integer
Dim sqlDataSet As New DataSet
Dim sqlDataAdapter As New sqlDataAdapter '执行对数据库进行操作的命令。
Dim sqlconnection As New sqlconnection '数据库接口。
Dim sqlConString As New conn '数据库链接的代码。
Dim sqlSelectCommand As String '执行查询命令的对象
Protected WithEvents ItemsGrid As System.Web.UI.WebControls.DataGrid
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If CheckBox1.Checked Then
ItemsGrid.PagerStyle.Mode = ItemsGrid.PagerStyle.Mode.NumericPages
Else
ItemsGrid.PagerStyle.Mode = ItemsGrid.PagerStyle.Mode.NextPrev
End If
If Not IsPostBack Then
start_index = 0
' ItemsGrid.VirtualItemCount = 100
BindGrid()
End If
End Sub
Sub BindGrid()
sqlconnection.ConnectionString = sqlConString.SQLConstr
sqlconnection.Open()
sqlSelectCommand = "SELECT Articleid,title,UpdateTime FROM Article ORDER BY Articleid DESC"
Dim sqlDataCommand As New SqlCommand(sqlSelectCommand, sqlconnection)
sqlDataAdapter.SelectCommand = sqlDataCommand
sqlDataAdapter.Fill(sqlDataSet, "Tarticle")
ItemsGrid.DataSource = sqlDataSet.Tables("Tarticle")
sqlconnection.Close()
ItemsGrid.DataBind()
End Sub
Sub Grid_Change(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles ItemsGrid.PageIndexChanged
ItemsGrid.CurrentPageIndex = e.NewPageIndex
start_index = ItemsGrid.CurrentPageIndex * ItemsGrid.PageSize
BindGrid()
End Sub
End Class
为什么不能翻页?
还有就AllowCustomPaging="True"谈谈分页的问题,我有一个表中300万条记录,而且基本每天在增加,如果分页,我该如何做,希望帮忙!
...全文
相关推荐
如何在DataGrid控件中实现自定义分页
如何在DataGrid控件中实现自定义分页 在一般情况下,DataGrid控件每次实现翻页操作时,都会将数据源中的数据重新调用一次,当数据中 数据很多时,这样做就会很浪费系统资源和降低程序的执行效率.这时候我们一般通过自定义分页来解 决这个问题. DataGrid控件的AllowCustomPaging属性用来获取或设置DataGrid控件是否允许自定义分 页;VirtualItemCoun属性用来获取或设置在使用自定义分页时DataGrid中实际的项数.要实现自定义分 页,必须将AllowPaging与AllowCustomPaging属性都设置为”True”. 在
ASPNet中DataGrid基于Access的快速分页法.docx
ASPNet中DataGrid基于Access的快速分页法.docx
ASP.NET中自定义DataGrid分页设置的实现
这里实现了DataGrid的个性化分页,现在把代码贴出来朋友们参考,同时在这个功能的实现过程,参考了“飞刀”从国外翻译的一篇文章。
DataList分页技巧方法
DataList分页技巧方法,助你实现分页的功能
深入DataList分页方法(利用PagedDataSource类)
利用PagedDataSource类深入DataList分页方法


