+ Reply to Thread
Results 1 to 7 of 7

Thread: paging enabled in a repeater control

  1. #1
    Barn Enthusiast peebman2000 is on a distinguished road peebman2000's Avatar
    Join Date
    Mar 2008
    Posts
    210
    Rep Power
    3

    paging enabled in a repeater control

    Hey everyone its peeb, a little busy here at the J O B. Hey does anyone know how to do paging with a repeater. The repeater is populated by data from the sqldatasource, but we're wanting to set up paging for it.

    Some of the articles online show you have to set up the paging somehow in code, i'm still researching it. Does anyone know how or have any good articles to set up paging in a repeater.

    Thanks and I appreciate any and all responses.

  2. #2
    Barn Enthusiast peebman2000 is on a distinguished road peebman2000's Avatar
    Join Date
    Mar 2008
    Posts
    210
    Rep Power
    3

    reply

    Hey everyone, i found this code here and I'm trying to practice with it, but i'm getting an error:

    Compilation Error
    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: BC30456: 'AllowPaging' is not a member of 'System.Web.UI.WebControls.Repeater'.

    Source Error:



    Line 22: myDA.Fill(ds, "t1")
    Line 23: pageds.DataSource = ds.Tables("t1").DefaultView
    Line 24: pageds.AllowPaging = True
    Line 25: Repeater1.PageSize = 4
    Line 26: Dim curpage As Integer

    This is my code, am I missing an import?
    Code:
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Dim ds As DataSet
            Dim pageds As New Repeater
            Dim myConnection As New SqlConnection(ConfigurationSettings.AppSettings("peebman"))
            Dim myDA As New SqlClient.SqlDataAdapter("Select * from peebtest2", myConnection)
            myDA.Fill(ds, "t1")
            pageds.DataSource = ds.Tables("t1").DefaultView
            pageds.AllowPaging = True
            Repeater1.PageSize = 4
            Dim curpage As Integer
    
            If Not IsNothing(Request.QueryString("Page")) Then
                curpage = Convert.ToInt32(Request.QueryString("Page"))
            Else
                curpage = 1
            End If
    
            pageds.CurrentPageIndex = curpage - 1
            lblCurrpage.Text = "Page: " + curpage.ToString()
    
            If Not pageds.IsFirstPage Then
                lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + _
                                               "?Page=" + CStr(curpage - 1)
            End If
    
            If Not pageds.IsLastPage Then
                lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + _
                                               "?Page=" + CStr(curpage + 1)
            End If
    
            Repeater1.DataSource = pageds
            Repeater1.DataBind()
    
        End Sub
    

  3. #3
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Washington, D.C.
    Posts
    2,347
    Blog Entries
    9
    Rep Power
    19

    It's because you're declaring pageds As New Repeater when it should be

    Code:
    Dim pageds As New PagedDataSource
    
    jmurrayhead
    If you agree, give me rep. If my post helped you, click "Thanks".
    If you like it here...throw us a few bones to help support us.


  4. #4
    Barn Enthusiast peebman2000 is on a distinguished road peebman2000's Avatar
    Join Date
    Mar 2008
    Posts
    210
    Rep Power
    3

    reply

    Okay thanks Jmurrayhead that worked but i'm still getting an error with the dataset:

    Server Error in '/testhelp3' Application.
    --------------------------------------------------------------------------------

    Value cannot be null.
    Parameter name: dataSet
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.ArgumentNullException: Value cannot be null.
    Parameter name: dataSet

    Source Error:


    Line 21: Dim myConnection As New SqlConnection(ConfigurationSettings.AppSettings("p eebman"))
    Line 22: Dim myDA As New SqlClient.SqlDataAdapter("Select * from peebtest2", myConnection)
    Line 23: myDA.Fill(ds, "t1")
    Line 24: pageds.DataSource = ds.Tables("t1").DefaultView
    Line 25: pageds.AllowPaging = True
    Code:
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Dim ds As DataSet = Nothing
            'Dim pageds As New Repeater
            Dim pageds As New PagedDataSource
            Dim myConnection As New SqlConnection(ConfigurationSettings.AppSettings("peebman"))
            Dim myDA As New SqlClient.SqlDataAdapter("Select * from peebtest2", myConnection)
            myDA.Fill(ds, "t1")
            pageds.DataSource = ds.Tables("t1").DefaultView
            pageds.AllowPaging = True
            pageds.PageSize = 4
            Dim curpage As Integer
    
            If Not IsNothing(Request.QueryString("Page")) Then
                curpage = Convert.ToInt32(Request.QueryString("Page"))
            Else
                curpage = 1
            End If
    
            pageds.CurrentPageIndex = curpage - 1
            currentpage.Text = "Page: " + curpage.ToString()
    
    
            'If Not pageds.IsFirstPage Then
            '    lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + _
            '                                   "?Page=" + CStr(curpage - 1)
            'End If
    
            'If Not pageds.IsLastPage Then
            '    lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + _
            '                                   "?Page=" + CStr(curpage + 1)
            'End If
    
            Repeater1.DataSource = pageds
            Repeater1.DataBind()
    
        End Sub
    

    I don't get it the dataset should work, the myDA.fill(ds, "ti") should fill the dataset with my select statment.



    Quote Originally Posted by jmurrayhead View Post
    It's because you're declaring pageds As New Repeater when it should be

    Code:
    Dim pageds As New PagedDataSource
    

  5. #5
    Barn Enthusiast peebman2000 is on a distinguished road peebman2000's Avatar
    Join Date
    Mar 2008
    Posts
    210
    Rep Power
    3

    reply

    I got it, i didn't declare the datas set as a new dataset.

    Code:
    Dim ds As DataSet
            ds = New DataSet
    
    I got another error, but i'm still working on it. give me a second.

  6. #6
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Washington, D.C.
    Posts
    2,347
    Blog Entries
    9
    Rep Power
    19

    Try the following example:

    Code:
        Public Property PageNumber() As Integer 
            Get 
                If ViewState("PageNumber") IsNot Nothing Then 
                    Return Convert.ToInt32(ViewState("PageNumber")) 
                Else 
                    Return 0 
                End If 
            End Get 
            Set 
                ViewState("PageNumber") = value 
            End Set 
        End Property 
        Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs) 
            MyBase.OnInit(e) 
            AddHandler rptPages.ItemCommand, AddressOf rptPages_ItemCommand 
        End Sub 
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) 
            If Not Page.IsPostBack Then 
                LoadData() 
            End If 
        End Sub 
        Private Sub LoadData() 
            Dim cn As New SqlConnection("your connection goes" & Chr(13) & "") 
            here 
            ");" & Chr(13) & "" 
            cn.Open() 
            Dim da As New SqlDataAdapter("your query goes" & Chr(13) & "") 
            here 
            ", cn);" & Chr(13) & "" 
            Dim dt As New DataTable() 
            da.Fill(dt) 
            cn.Close() 
            Dim pgitems As New PagedDataSource() 
            Dim dv As New DataView(dt) 
            pgitems.DataSource = dv 
            pgitems.AllowPaging = True 
            pgitems.PageSize = 25 
            pgitems.CurrentPageIndex = PageNumber 
            If pgitems.PageCount > 1 Then 
                rptPages.Visible = True 
                Dim pages As New ArrayList() 
                For i As Integer = 0 To pgitems.PageCount - 1 
                    pages.Add((i + 1).ToString()) 
                Next 
                rptPages.DataSource = pages 
                rptPages.DataBind() 
            Else 
                rptPages.Visible = False 
            End If 
            rptItems.DataSource = pgitems 
            rptItems.DataBind() 
        End Sub 
        Private Sub rptPages_ItemCommand(ByVal source As Object, ByVal e As RepeaterCommandEventArgs) 
            PageNumber = Convert.ToInt32(e.CommandArgument) - 1 
            LoadData() 
        End Sub
    
    Code:
    <asp:Repeater ID="rptPages" Runat="server">
          <HeaderTemplate>
          <table cellpadding="0" cellspacing="0" border="0">
          <tr class="text">
             <td><b>Page:</b>&nbsp;</td>
             <td>
          </HeaderTemplate>
          <ItemTemplate>
             <asp:LinkButton ID="btnPage"
                             CommandName="Page"
                             CommandArgument="<%#
                             Container.DataItem %>"
                             CssClass="text"
                             Runat="server"><%# Container.DataItem %>
                             </asp:LinkButton>&nbsp;
          </ItemTemplate>
          <FooterTemplate>
             </td>
          </tr>
          </table>
          </FooterTemplate>
          </asp:Repeater>
          <asp:Repeater ID="rptItems" runat="server">
          <HeaderTemplate>
          <ul>
          </HeaderTemplate>
          <ItemTemplate>
          <li><%# Eval("pkItemID") %>: <%# Eval("Description") %></li>
          </ItemTemplate>
          <FooterTemplate>
          </ul>
          </FooterTemplate>
          </asp:Repeater>
    
    Your example uses a DataSet, which should be used if you are filling it with more than one table. Otherwise, it is overkill. The above example uses a DataTable.
    jmurrayhead
    If you agree, give me rep. If my post helped you, click "Thanks".
    If you like it here...throw us a few bones to help support us.


  7. #7
    Barn Enthusiast peebman2000 is on a distinguished road peebman2000's Avatar
    Join Date
    Mar 2008
    Posts
    210
    Rep Power
    3

    reply

    Hey thanks jmurrayhead, I was able to get it with the dataset. The other error I got was with my connections string, it didn't like it.

    I see what you saying with the datatable, i'll try that, but now I have an understanding for paging with a repeater.

    Thanks for the reply, take care.

    Quote Originally Posted by jmurrayhead View Post
    Try the following example:

    Code:
        Public Property PageNumber() As Integer 
            Get 
                If ViewState("PageNumber") IsNot Nothing Then 
                    Return Convert.ToInt32(ViewState("PageNumber")) 
                Else 
                    Return 0 
                End If 
            End Get 
            Set 
                ViewState("PageNumber") = value 
            End Set 
        End Property 
        Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs) 
            MyBase.OnInit(e) 
            AddHandler rptPages.ItemCommand, AddressOf rptPages_ItemCommand 
        End Sub 
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) 
            If Not Page.IsPostBack Then 
                LoadData() 
            End If 
        End Sub 
        Private Sub LoadData() 
            Dim cn As New SqlConnection("your connection goes" & Chr(13) & "") 
            here 
            ");" & Chr(13) & "" 
            cn.Open() 
            Dim da As New SqlDataAdapter("your query goes" & Chr(13) & "") 
            here 
            ", cn);" & Chr(13) & "" 
            Dim dt As New DataTable() 
            da.Fill(dt) 
            cn.Close() 
            Dim pgitems As New PagedDataSource() 
            Dim dv As New DataView(dt) 
            pgitems.DataSource = dv 
            pgitems.AllowPaging = True 
            pgitems.PageSize = 25 
            pgitems.CurrentPageIndex = PageNumber 
            If pgitems.PageCount > 1 Then 
                rptPages.Visible = True 
                Dim pages As New ArrayList() 
                For i As Integer = 0 To pgitems.PageCount - 1 
                    pages.Add((i + 1).ToString()) 
                Next 
                rptPages.DataSource = pages 
                rptPages.DataBind() 
            Else 
                rptPages.Visible = False 
            End If 
            rptItems.DataSource = pgitems 
            rptItems.DataBind() 
        End Sub 
        Private Sub rptPages_ItemCommand(ByVal source As Object, ByVal e As RepeaterCommandEventArgs) 
            PageNumber = Convert.ToInt32(e.CommandArgument) - 1 
            LoadData() 
        End Sub
    
    Code:
    <asp:Repeater ID="rptPages" Runat="server">
          <HeaderTemplate>
          <table cellpadding="0" cellspacing="0" border="0">
          <tr class="text">
             <td><b>Page:</b>&nbsp;</td>
             <td>
          </HeaderTemplate>
          <ItemTemplate>
             <asp:LinkButton ID="btnPage"
                             CommandName="Page"
                             CommandArgument="<%#
                             Container.DataItem %>"
                             CssClass="text"
                             Runat="server"><%# Container.DataItem %>
                             </asp:LinkButton>&nbsp;
          </ItemTemplate>
          <FooterTemplate>
             </td>
          </tr>
          </table>
          </FooterTemplate>
          </asp:Repeater>
          <asp:Repeater ID="rptItems" runat="server">
          <HeaderTemplate>
          <ul>
          </HeaderTemplate>
          <ItemTemplate>
          <li><%# Eval("pkItemID") %>: <%# Eval("Description") %></li>
          </ItemTemplate>
          <FooterTemplate>
          </ul>
          </FooterTemplate>
          </asp:Repeater>
    
    Your example uses a DataSet, which should be used if you are filling it with more than one table. Otherwise, it is overkill. The above example uses a DataTable.

+ Reply to Thread

Similar Threads

  1. Paging
    By Shem in forum .Net Development
    Replies: 3
    Last Post: July 21st, 2009, 04:23 AM
  2. convert repeater to pdf
    By peebman2000 in forum .Net Development
    Replies: 4
    Last Post: August 18th, 2008, 09:39 AM
  3. Generic Paging Class
    By Shem in forum .Net Development
    Replies: 4
    Last Post: July 18th, 2008, 11:29 AM
  4. adding an event for my btnDelete in repeater
    By Shem in forum .Net Development
    Replies: 13
    Last Post: July 15th, 2008, 09:33 AM
  5. HttpException - Session State not enabled.
    By Wolffy in forum .Net Development
    Replies: 3
    Last Post: May 21st, 2008, 09:40 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO