我用AllowCustomPaging="True"方法,实际datagrid分页,为什么不行,求完整解决方案!

clkun clkun 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
<%@ 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万条记录,而且基本每天在增加,如果分页,我该如何做,希望帮忙!
...全文

相关推荐

评论 11
收藏 已收藏
分享
返回顶部
clkun
.NET社区 62,274 成员 668,968 内容