![]() |
| |||||||
| Sponsored Links |
![]() | « Previous Thread | Next Thread » |
| | LinkBack | Thread Tools | Display Modes |
|
#1
| |||
| |||
| 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. |
| Sponsored Links |
|
#2
| |||
| |||
| Hey everyone, i found this code here and I'm trying to practice with it, but i'm getting an error: Quote:
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
| ||||
| ||||
| 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 |
|
#4
| |||
| |||
| Okay thanks Jmurrayhead that worked but i'm still getting an error with the dataset: Quote:
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. |
|
#5
| |||
| |||
| I got it, i didn't declare the datas set as a new dataset. Code: Dim ds As DataSet
ds = New DataSet
|
|
#6
| ||||
| ||||
| 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> </td>
<td>
</HeaderTemplate>
<ItemTemplate>
<asp:LinkButton ID="btnPage"
CommandName="Page"
CommandArgument="<%#
Container.DataItem %>"
CssClass="text"
Runat="server"><%# Container.DataItem %>
</asp:LinkButton>
</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>
|
| The Following User Says Thank You to jmurrayhead For This Useful Post: | ||
peebman2000 (September 4th, 2008) | ||
|
#7
| |||
| |||
| 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:
|
![]() |
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
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 |