国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

datagrid分頁問題(前后跳頁)《控件版》

2024-07-21 02:24:23
字體:
來源:轉載
供稿:網友

最大的網站源碼資源下載站,

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 尚义县| 田林县| 微博| 三明市| 孝感市| 外汇| 连州市| 西乌珠穆沁旗| 杭锦后旗| 平邑县| 马关县| 北京市| 苍山县| 开封市| 桃源县| 桃园市| 依兰县| 南昌市| 德清县| 蒲江县| 洛宁县| 凯里市| 黑河市| 象州县| 亳州市| 日喀则市| 福安市| 潞城市| 长子县| 太仓市| 田林县| 来凤县| 双鸭山市| 东乌珠穆沁旗| 莆田市| 蓝山县| 商水县| 全椒县| 彭山县| 囊谦县| 永靖县|