18/02/2008, 14:52
|
| | Fecha de Ingreso: mayo-2007
Mensajes: 2
Antigüedad: 17 años, 7 meses Puntos: 0 | |
Re: Paginar un DataList Te envio un ejemplo que lo encontré por ahi, y funciona...
Chispas, es un poco largo... pongo el que NO necesita un datasource, para que tengas una idea, y si te complicas escribes otra ves...
Saludos..
Pd. Pega todo en una un webform
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<script runat="server">
Dim pagedData As New pagedDataSource
Sub Page_Load(byVal obj As Object, byVal e As EventArgs)
doPaging()
End Sub
Sub doPaging()
Dim mockData As New HashTable()
Dim IDx As Integer = 0
Do Until IDx = 500
mockData.Add(IDx.toString(), (IDx * 101).toString)
IDx += 1
Loop
pagedData.DataSource = mockData
pagedData.AllowPaging = True
pagedData.PageSize = 5
Try
pagedData.CurrentPageIndex = Int32.Parse(Request.QueryString("Page")).ToString( )
Catch ex As Exception
pagedData.CurrentPageIndex = 0
End Try
btnPrev.Visible = ( NOT pagedData.IsFirstPage )
btnNext.Visible = ( NOT pagedData.IsLastPage )
theDataList.DataSource = pagedData
theDataList.DataBind()
End Sub
Public Sub Prev_Click(ByVal obj As Object, ByVal e As EventArgs)
Response.Redirect(Request.CurrentExecutionFilePath & "?Page=" & (pagedData.CurrentPageIndex - 1))
End Sub
Public Sub Next_Click(ByVal obj As Object, ByVal e As EventArgs)
Response.Redirect(Request.CurrentExecutionFilePath & "?Page=" & (pagedData.CurrentPageIndex + 1))
End Sub
</script>
<html>
<head>
<title>Paging with ASP.NET - HashTable Example - VB.NET</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form runat="server">
<asp:DataList id="theDataList" runat="server">
<ItemTemplate>
<hr size="0" />
Department: <%# DataBinder.Eval(Container.DataItem, "Key") %><br />
Employee ID: <%# DataBinder.Eval(Container.DataItem, "Value") %></a><br />
</ItemTemplate>
</asp:DataList>
<asp:LinkButton id="btnPrev" Text="<" OnClick="Prev_Click" runat="server" />
<asp:LinkButton id="btnNext" Text=">" OnClick="Next_Click" runat="server" />
</form>
</body>
</html> |