Versão: 1.0
Funcionalidade: Realiza paginação no Repeater
<%@ Page Language="vb" %> <%@ import Namespace="System.Data" %> <%@ import Namespace="System.Data.SqlClient" %> <script runat="server"> Sub Page_Load(Sender As Object, e As EventArgs) Dim myConnection As New SqlConnection("server=localhost;uid=cris;pwd=cris;database=pubs") myConnection.Open() Dim strSql As String = "select * from authors" Dim objPds As PagedDataSource = new PagedDataSource() Dim dr As SqlDataAdapter = New SqlDataAdapter(strSql, myConnection) Dim ds As DataSet = new DataSet() Dim CurPage As Integer dr.Fill(ds) Dim intCount As Integer = ds.Tables(0).Rows.Count If intCount = 0 Then panelCategorias.Visible=False lblNoCategorias.Text = "<br><font>Não ha registros</font>" lblNoCategorias.Visible=True Else lblNoCategorias.Visible=False End If objPds.DataSource = ds.Tables(0).DefaultView objPds.AllowPaging = true objPds.PageSize = 5 If Not Request.QueryString("p") Is Nothing Then CurPage=CInt(Request.QueryString("p")) Else CurPage=0 End If objPds.CurrentPageIndex = CurPage ''-1 lblCurrentPage.Text = "Page: " + CurPage.ToString() If Not objPds.IsFirstPage Then lnkPrev.NavigateUrl=Request.CurrentExecutionFilePath + "?p=" + Convert.ToString(CurPage-1) End If If Not objPds.IsLastPage Then lnkNext.NavigateUrl=Request.CurrentExecutionFilePath+ "?p=" + Convert.ToString(CurPage+1) End If gridCategorias.DataSource = objPds gridCategorias.DataBind() End Sub </script> <center> <asp:Label id="lblNoCategorias" runat="server" /> </center> <asp:Panel id="panelCategorias" runat="server"> <asp:DataList id="gridCategorias" runat="server"> <headertemplate> <b>Nome</b><br> </headertemplate> <itemtemplate> <%# DataBinder.Eval (Container.DataItem, "au_lname") %><br> </itemtemplate> </asp:Datalist> <asp:label id="lblCurrentPage" runat="server" Visible="True"></asp:label> <br> <asp:HyperLink id="lnkPrev" runat="server" CssClass="campos"><< Anterior</asp:HyperLink> <asp:HyperLink id="lnkNext" runat="server" CssClass="campos">Próxima >></asp:HyperLink> </asp:Panel>
Publicado em : http://www.codigofor...JTIJLSP8J60VXCE