Go Back   DeveloperBarn Forums > Programming & Scripting > .Net Development

Sponsored Links

Discuss "paging enabled in a repeater control" in the .Net Development forum.

.Net Development - Learn about the Microsoft.Net framework and how to create powerful web-based (ASP.net) and client-based (Windows Forms) applications utilizing various languages such as C#, VB.Net, J# and others.


Reply « Previous Thread | Next Thread »  
 
LinkBack Thread Tools Display Modes
  #1  
Old September 4th, 2008, 09:50 AM
Barn Frequenter

 
Join Date: Mar 2008
Posts: 174
Thanks: 14
Thanked 0 Times in 0 Posts
Rep Power: 1
peebman2000 is an unknown quantity at this point
Question 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.
Reply With Quote
Sponsored Links
  #2  
Old September 4th, 2008, 10:36 AM
Barn Frequenter

 
Join Date: Mar 2008
Posts: 174
Thanks: 14
Thanked 0 Times in 0 Posts
Rep Power: 1
peebman2000 is an unknown quantity at this point
Question reply

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

Quote:
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
Reply With Quote
  #3  
Old September 4th, 2008, 10:49 AM
jmurrayhead's Avatar
The Barnfather

 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 820
Thanks: 20
Thanked 74 Times in 71 Posts
Blog Entries: 5
Rep Power: 3
jmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura about

Awards Showcase
Microsoft .Net Microsoft SQL Server Microsoft Windows Classic ASP 
Total Awards: 4

Default

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

Code:
Dim pageds As New PagedDataSource
__________________
jmurrayhead
If you agree with me... click the icon!
If my post solved your problem, click the button in the lower right-hand corner of the post.

Join our Folding team: DeveloperBarn Folding
Reply With Quote
  #4  
Old September 4th, 2008, 10:56 AM
Barn Frequenter

 
Join Date: Mar 2008
Posts: 174
Thanks: 14
Thanked 0 Times in 0 Posts
Rep Power: 1
peebman2000 is an unknown quantity at this point
Question reply

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

Quote:
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
Reply With Quote
  #5  
Old September 4th, 2008, 11:03 AM
Barn Frequenter

 
Join Date: Mar 2008
Posts: 174
Thanks: 14
Thanked 0 Times in 0 Posts
Rep Power: 1
peebman2000 is an unknown quantity at this point
Question 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.
Reply With Quote
  #6  
Old September 4th, 2008, 11:08 AM
jmurrayhead's Avatar
The Barnfather

 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 820
Thanks: 20
Thanked 74 Times in 71 Posts
Blog Entries: 5
Rep Power: 3
jmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura about

Awards Showcase
Microsoft .Net Microsoft SQL Server Microsoft Windows Classic ASP 
Total Awards: 4

Default

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.

Comments on this post
peebman2000 agrees: Thanked Post
Reply With Quote
The Following User Says Thank You to jmurrayhead For This Useful Post:
peebman2000 (September 4th, 2008)
  #7  
Old September 4th, 2008, 11:15 AM
Barn Frequenter

 
Join Date: Mar 2008
Posts: 174
Thanks: 14
Thanked 0 Times in 0 Posts
Rep Power: 1
peebman2000 is an unknown quantity at this point
Thumbs up 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 With Quote
Reply

  DeveloperBarn Forums > Programming & Scripting > .Net Development

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

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


All times are GMT -4. The time now is 07:56 PM.



Content Relevant URLs by vBSEO 3.2.0