GridView自定义分页

macroq 2009-09-04 11:18:11
我要一个VB的版本的,但都只找到C#的,哪位能帮忙提供或改写一份VB的给我,不甚感激。

html

<pagertemplate>
<table width="100%">
<tr>
<td style="text-align:right">
第<asp:Label id="lblPageIndex" runat="server" text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' />页
共/<asp:Label id="lblPageCount" runat="server" text='<%# ((GridView)Container.Parent.Parent).PageCount %>' />页
<asp:linkbutton id="btnFirst" runat="server" causesvalidation="False" commandargument="First" commandname="Page" text="首页" />
<asp:linkbutton id="btnPrev" runat="server" causesvalidation="False" commandargument="Prev" commandname="Page" text="上一页" />
<asp:linkbutton id="btnNext" runat="server" causesvalidation="False" commandargument="Next" commandname="Page" text="下一页" />
<asp:linkbutton id="btnLast" runat="server" causesvalidation="False" commandargument="Last" commandname="Page" text="尾页" />
<asp:textbox id="txtNewPageIndex" runat="server" width="20px" text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' />
<asp:linkbutton id="btnGo" runat="server" causesvalidation="False" commandargument="-1" commandname="Page" text="GO" /><!-- here set the CommandArgument of the Go Button to '-1' as the flag -->
</td>
</tr>
</table>
</pagertemplate>


c#

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView theGrid = sender as GridView;
int newPageIndex = 0;

if (-2 == e.NewPageIndex)
{
TextBox txtNewPageIndex = null;
GridViewRow pagerRow = theGrid.BottomPagerRow;

if (null != pagerRow)
{
txtNewPageIndex = pagerRow.FindControl("txtNewPageIndex") as TextBox;
}

if (null != txtNewPageIndex)
{
newPageIndex = int.Parse(txtNewPageIndex.Text) - 1;
}
}
else
{
newPageIndex = e.NewPageIndex;
}

newPageIndex = newPageIndex < 0 ? 0 : newPageIndex;
newPageIndex = newPageIndex >= theGrid.PageCount ? theGrid.PageCount - 1 : newPageIndex;

theGrid.PageIndex = newPageIndex;

}
...全文
202 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lwd203 2009-09-04
  • 打赏
  • 举报
回复
Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As GridViewPageEventArgs)
Dim theGrid As GridView = TryCast(sender, GridView)
Dim newPageIndex As Integer = 0

If -2 = e.NewPageIndex Then
Dim txtNewPageIndex As TextBox = Nothing
Dim pagerRow As GridViewRow = theGrid.BottomPagerRow

If pagerRow IsNot Nothing Then
txtNewPageIndex = TryCast(pagerRow.FindControl("txtNewPageIndex"), TextBox)
End If

If txtNewPageIndex IsNot Nothing Then
newPageIndex = Integer.Parse(txtNewPageIndex.Text) - 1
End If
Else
newPageIndex = e.NewPageIndex
End If

newPageIndex = If(newPageIndex < 0, 0, newPageIndex)
newPageIndex = If(newPageIndex >= theGrid.PageCount, theGrid.PageCount - 1, newPageIndex)


theGrid.PageIndex = newPageIndex
End Sub

lwd203 2009-09-04
  • 打赏
  • 举报
回复
大同小异,你google搜C#转vb.net,很多
水哥阿乐 2009-09-04
  • 打赏
  • 举报
回复

CloneCenter 2009-09-04
  • 打赏
  • 举报
回复
把 C# 代码转换为 VB.NET 就可以了。
flyerwing 2009-09-04
  • 打赏
  • 举报
回复
一样的了,代码很简单,主要是界面上的。
哎。
macroq 2009-09-04
  • 打赏
  • 举报
回复
多谢大家,已经解决!

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧