在ASCX中寫的。
在CSDN上看了很多的DATAGRID分頁問題,當然DATAGRID有自己的分頁項,功能是很有限的,我也在CSDN上看了很多自己分頁的代碼,發現都是用C#寫的,我寫了一個用ASP。NET中VB語言寫的。以下代碼供大家參考。
HTML代碼:
<%@ Control Language="vb" AutoEventWireup="false" Codebehind="DataGridPage.ascx.vb" Inherits="datagridfenye.DataGridPage" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<LINK href="../css/style.css" type="text/css" rel="stylesheet">
<FONT face="MS UI Gothic"></FONT>
<asp:panel id="divPanel" ForeColor="Blue" CssClass="font2" HorizontalAlign="Left" Width="84.16%"
runat="server" Visible="True">
<asp:Button id="btnNavFirst" runat="server" BorderStyle="Ridge" Text="初頁" CommandName="FIRST"
BorderWidth="1px" CausesValidation="False" BackColor="#E0E0E0" Font-Size="XX-Small"></asp:Button>
<asp:Button id="btnNavPrevious" runat="server" BorderStyle="Ridge" Text="前頁" CommandName="PREVIOUS"
BorderWidth="1px" CausesValidation="False" BackColor="#E0E0E0" Font-Size="XX-Small"></asp:Button>
<asp:Button id="btnNavNext" runat="server" BorderStyle="Ridge" Text="次頁" CommandName="NEXT"
BorderWidth="1px" CausesValidation="False" BackColor="#E0E0E0" Font-Size="XX-Small"></asp:Button>
<asp:Button id="btnNavLast" runat="server" BorderStyle="Ridge" Text="末頁" CommandName="LAST"
BorderWidth="1px" CausesValidation="False" BackColor="#E0E0E0" Font-Size="XX-Small"></asp:Button><INPUT id="hdRowCount" style="WIDTH: 43px; HEIGHT: 22px" type="hidden" size="1" name="Hidden1"
runat="server"> <INPUT id="hdCurrentIndex" style="WIDTH: 48px; HEIGHT: 22px" type="hidden" size="2" value="0"
name="Hidden1" runat="server">
<asp:Label id="LabelMsg" ForeColor="Blue" Width="232px" runat="server"></asp:Label>GOTO
<asp:TextBox id="tbPage" Width="31px" runat="server"></asp:TextBox>
<asp:Label id="LabelMsg2" ForeColor="Blue" runat="server">頁</asp:Label>
<asp:Button id="btnNavGo" runat="server" BorderStyle="Ridge" Text="確定" CommandName="GO" BorderWidth="1px"
CausesValidation="False" BackColor="#E0E0E0" Font-Size="XX-Small"></asp:Button></asp:panel>
<%@ Control Language="vb" AutoEventWireup="false" Codebehind="DataGridPage.ascx.vb" Inherits="datagridfenye.DataGridPage" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
WEB代碼:
Imports System
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Web
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Public Delegate Sub BindDataDelegate()
Public Class DataGridPage
Inherits System.Web.UI.UserControl
#Region " Web フォーム デザイナで生成されたコード "
'この呼び出しは Web フォーム デザイナで必要です。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Public binddata1 As BindDataDelegate
Private _dg As DataGrid
Private _autohidden As Boolean = True
Private _pagesize As Integer = 10
Private _itemcount As Integer = 0
Private _dispStyle As Integer = 1
Protected WithEvents LabelMsg As System.Web.UI.WebControls.Label
Protected WithEvents btnNavFirst As System.Web.UI.WebControls.Button
Protected WithEvents btnNavPrevious As System.Web.UI.WebControls.Button
Protected WithEvents btnNavNext As System.Web.UI.WebControls.Button
Protected WithEvents btnNavLast As System.Web.UI.WebControls.Button
Protected WithEvents tbPage As System.Web.UI.WebControls.TextBox
Protected WithEvents LabelMsg2 As System.Web.UI.WebControls.Label
Protected WithEvents btnNavGo As System.Web.UI.WebControls.Button
Protected WithEvents divPanel As System.Web.UI.WebControls.Panel
Protected WithEvents hdRowCount As System.Web.UI.HtmlControls.HtmlInputHidden
Protected WithEvents hdCurrentIndex As System.Web.UI.HtmlControls.HtmlInputHidden