DataGrid page issues (front and rear page) "Control Edition inherited UserControl"

zhaozj2021-02-16  58

Define it in the user control. in. Written in ASCX.

After 9CBS, I saw a lot of DataGrid page issues. Of course, DataGrid has its own pagination item. The function is very limited. I also read a lot of my own code on 9cbs. I found that I wrote it with C #, I wrote a Use ASP. Written in the VB in NET. The following code is for your reference.

HTML code:

<% @ 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"> < / asp: button> goto page web code:

Imports SystemImports System.DataImports System.DrawingImports System.TextImports System.WebImports System.Web.UI.WebControlsImports System.Web.UI.HtmlControlsPublic Delegate Sub BindDataDelegate () Public Class DataGridPage

Inherits System.Web.ui.userControl

#REGON "Web フォ フォ ム デザ ナ ナ 生 れ れ コ コ ド"

'こ こ び し ​​は Web フォ フォ ム デザ で で 必 必 必 必 必 必 必 必 必. ナ private subinitializecomponent ()

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.htm LINPUTHIDDEN 'メモ: プレ プレ ス ホ ホ ダ ダ 言 Web フォ フォ ム デザ ナ で で 必 必 必 必 必 必 す 必 デザ す す す す デザ'Removing および および および し で.. Private DesignerPlaceHolderDeclaration as System.Object

Private Sub Page_init (Byval e as system.Object, byval e as system.eventargs) Handles mybase.init 'codegen: こ こ メソ ド ド び し フォ 必 必 必 必 す 必 必 必 必 必 す. ナ. ナ ナ.. ナ ナ ナ ナ ナ ナ 必 デザ ナ 必 必 ナ 必 デザ デザ 必 ナ デザ 必 ナ ナ ナ ナ ナ デザ 必 必 必 必 必 必 必 必 デザ 必 必 必 必 必 必 必 必 デザ デザ す す 必 デザ デザ デザ デザ デザ デザ デザ デザ デザ. デザ デザ デザ デザ デザ デザ デザ デザ デザ デザ デザ'コ コ ド ド エディ っ っ て 変 変.. くだ くだ くだ くだ くだ い っ くだ くだ い い くだ い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 data "_dg = value end vend" as boolean

Get return _autohidden end set (byval value as boolean) _autohidden = value end vendypublic protrop1ize () AS INTEGER

Get return _PageSize End Get Set (BYVAL VALUE AS INTEGER) _PAGESIZE = Value End End Property Public Property Itemcount () AS Integer

Get return _itemcount end set (byval value as integer) _Itemcount = value end vendy

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 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 e as system.eventargs) DIM DIRECTION AS STRING DIRECTION = sender.commandnameselect 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 E AS ISTEM.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.dataource.rows.count

Elseif (_dg.datasource.gettype (). TOSTRING (). TOLOWER () = "system.data.dataview") THEN

Newcount = _dg.dataource.count

Elseif (_dg.datasource.gettype (). Tostring (). TOLOWER () = "system.data.dataset") ThenneWCount = _dg.dataSource.tables (0) .rows.count endiff

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 = "Total" pageCount.toString () "page" (_dg.currentpageindex 1) .tostring () "page" labelmsg.text = "Total number:" newcount .Tostring () ""

Case 2 labelmsg.text = (_dg.currentpageindex 1) .tostring () "/" page "labelmsg.text =" total: " 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

转载请注明原文地址:https://www.9cbs.com/read-21952.html

New Post(0)