分享
 
 
 

datagrid分页问题(前后跳页)《控件版》

王朝c#·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

把它定义在用户控件中的。在。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>

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

'メモ : 次のプレースホルダ宣言は 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()

AddHandler Me.Load, AddressOf Page_Load

End Sub

#End Region

Public Property Target() As DataGrid

Get

Return _dg

End Get

Set(ByVal Value As DataGrid)

_dg = Value

End Set

End Property

Public Property AutoHidden() As Boolean

Get

Return _autohidden

End Get

Set(ByVal Value As Boolean)

_autohidden = Value

End Set

End Property

Public Property PageSize() As Integer

Get

Return _pagesize

End Get

Set(ByVal Value As Integer)

_pagesize = Value

End Set

End Property

Public Property ItemCount() As Integer

Get

Return _itemcount

End Get

Set(ByVal Value As Integer)

_itemcount = Value

End Set

End Property

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

' ページを初期化するユーザー コードをここに挿入します。

End Sub

Public Sub SetTarget(ByVal adg As DataGrid, ByRef aBindData1 As BindDataDelegate)

_dg = adg

binddata1 = aBindData1

AddHandler btnNavFirst.Click, AddressOf NavigationButtonClick

AddHandler btnNavPrevious.Click, AddressOf NavigationButtonClick

AddHandler btnNavNext.Click, AddressOf NavigationButtonClick

AddHandler btnNavLast.Click, AddressOf NavigationButtonClick

AddHandler btnNavGo.Click, AddressOf NavigationButtonClick

AddHandler _dg.DataBinding, AddressOf zxDataBinding

binddata1()

End Sub

Public Sub SetStyle(ByVal aPageSize As Integer, ByVal aAutoHidden As Boolean, ByVal aDispStyle As Integer)

_pagesize = aPageSize

_autohidden = aAutoHidden

_dispStyle = aDispStyle

divPanel.Visible = Not aAutoHidden

End Sub

Public Sub SetStyle(ByVal aPageSize As Integer, ByVal aAutoHidden As Boolean)

SetStyle(aPageSize, aAutoHidden, 1)

End Sub

Public Sub SetStyle(ByVal aPageSize As Integer)

SetStyle(aPageSize, True)

End Sub

Public Sub NavigationButtonClick(ByVal sender As Object, ByVal e As System.EventArgs)

Dim direction As String

direction = sender.CommandName

Select Case (direction.ToUpper())

Case ("FIRST")

_dg.CurrentPageIndex = 0

Case ("PREVIOUS")

_dg.CurrentPageIndex = Math.Max(_dg.CurrentPageIndex - 1, 0)

Case ("NEXT")

_dg.CurrentPageIndex = Math.Min(_dg.CurrentPageIndex + 1, _dg.PageCount - 1)

Case ("LAST")

_dg.CurrentPageIndex = Math.Max(_dg.PageCount - 1, 0)

Case ("GO")

Try

_dg.CurrentPageIndex = Math.Min(_dg.PageCount - 1, CInt(tbPage.Text) - 1)

tbPage.Text = ""

Catch

tbPage.Text = ""

End Try

End Select

binddata1()

End Sub

Public Sub zxDataBinding(ByVal sender As Object, ByVal e As System.EventArgs)

Dim newCount As Integer = 0

Dim PageCount As Integer = 0

If (_dg.DataSource Is "null") Then

SetButtonState(0)

Exit Sub

End If

If (_dg.DataSource.GetType().ToString().ToLower() = "system.data.datatable") Then

newCount = _dg.DataSource.Rows.Count

ElseIf (_dg.DataSource.GetType().ToString().ToLower() = "system.data.dataview") Then

newCount = _dg.DataSource.Count

ElseIf (_dg.DataSource.GetType().ToString().ToLower() = "system.data.dataset") Then

newCount = _dg.DataSource.Tables(0).Rows.Count

End If

If (newCount > 0) Then

PageCount = CInt((newCount - 1) / _pagesize)

If (_dg.CurrentPageIndex > PageCount - 1) Then

_dg.CurrentPageIndex = PageCount - 1

End If

Else

PageCount = 0

_dg.CurrentPageIndex = 0

End If

Select Case (_dispStyle)

Case 1

LabelMsg.Text = "共" + PageCount.ToString() + "頁 第" + (_dg.CurrentPageIndex + 1).ToString() + "頁"

LabelMsg.Text += " 總記?數:" + newCount.ToString() + ""

Case 2

LabelMsg.Text = (_dg.CurrentPageIndex + 1).ToString() + "/" + PageCount.ToString() + "頁"

LabelMsg.Text += " 總數:" + newCount.ToString()

End Select

If (_autohidden) Then

divPanel.Visible = ((newCount - 1) / _pagesize > 0)

Else

divPanel.Visible = True

End If

SetButtonState(PageCount)

End Sub

Public Sub SetButtonState(ByVal _PageCount As Integer)

btnNavFirst.Enabled = (_dg.CurrentPageIndex > 0)

btnNavPrevious.Enabled = (_dg.CurrentPageIndex > 0)

btnNavNext.Enabled = (_dg.CurrentPageIndex < _PageCount - 1)

btnNavLast.Enabled = (_dg.CurrentPageIndex < _PageCount - 1)

End Sub

End Class

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有