Datagrid分页(上一页,下一页没有链接)

庄子 2008-08-27 05:45:47
<%@ Page Language="VB" %>

<%@ import Namespace ="system.Data" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<script runat="server">
Dim start_index As Integer
Function CreateDataSource() As ICollection
Dim dt As DataTable = New DataTable()
Dim dr As DataRow
Dim i As Integer
dt.Columns.Add(New DataColumn("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn("CurrencyValue", GetType(Double)))
For i = start_index To (start_index + ItemGrid.PageSize) - 1
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item" + i.ToString
dr(2) = 3.9 * (i + 1)
dt.Rows.Add(dr)
Next i
Dim Dv As DataView = New DataView(dt)
Return Dv
End Function

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
If CheckBox1.Checked Then
ItemGrid.PagerStyle.Mode = PagerMode.NumericPages
Else
ItemGrid.PagerStyle.Mode = PagerMode.NextPrev
End If

If Not IsPostBack Then
start_index = 0
ItemGrid.VirtualItemCount = 100
End If
BindGrid()
End Sub

Sub Grid_Change(ByVal Sender As Object, ByVal e As DataGridPageChangedEventArgs)
ItemGrid.CurrentPageIndex = e.NewPageIndex
start_index = ItemGrid.CurrentPageIndex * ItemGrid.PageSize
BindGrid()
End Sub

Sub BindGrid()
ItemGrid.DataSource = CreateDataSource()
ItemGrid.DataBind()
End Sub

</script>


<head id="Head1" runat="server">
<title>无标题页</title>
</head>
<body>

<form id="form1" runat="server">
<h3>DataGrid显示</h3>
<b>产品列表</b>
<asp:DataGrid ID="ItemGrid" AllowPaging ="true" PageSize ="5" ItemStyle-HorizontalAlign ="center" BackColor ="green" CellPadding ="3" CellSpacing="3" AutoGenerateColumns ="false" OnPageIndexChanged ="Grid_Change" runat ="server" >

<PagerStyle NextPageText ="下一页"
PrevPageText ="上一页"
Position ="bottom"
PageButtonCount ="3"
BackColor = "white" />
<AlternatingItemStyle BackColor ="white" />


<HeaderStyle BackColor ="blue" />
<Columns>
<asp:BoundColumn HeaderText ="Number" DataField ="IntegerValue"></asp:BoundColumn>
<asp:BoundColumn HeaderText ="Item" DataField ="StringValue"></asp:BoundColumn>
<asp:BoundColumn Headertext ="Price" DataField ="CurrencyValue" DataFormatString ="{0:c}"></asp:BoundColumn>
</Columns>

</asp:DataGrid>
<br />
<asp:CheckBox Text="显示导航页" ID="CheckBox1" runat="server" AutoPostBack ="true" />

</form>
</body>
</html>
...全文
48 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
浮生若梦丶 2008-08-27
  • 打赏
  • 举报
回复
你的后台代码里 的分页事件写没有?我学c#的

62,025

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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