carecorejen
asked on
ASP.NET 2.0 Datalist and Paging
I am trying to set up paging with a .NET 2.0 Datalist. I have pretty much succeeded to implement it using a PagedDataSource. My only remaining issue is that I want the page controls to look something like:
<| << 1 2 3 4 5 >> |>
I've got it working except that the current page is ALWAYS the first page in the list. So, if I click on 5, 5 becomes the first item in the list. With the exception of Page 1 & 2, I'd like the first page in the list to be the third item. How do I do that?
Here's what I've got:
Dim conn As SqlConnection
Dim ds As New DataSet
Dim adapter As SqlDataAdapter
' Read the connection string from Web.config
Dim connectionString As String = ConfigurationManager.Conne ctionStrin g.("Connec tionString ").Connect ionString
' Initialize connection
conn = New SqlConnection(connectionSt ring)
'use a stored proc
'Not getting SQL Statement!
adapter = New SqlDataAdapter(SqlDataSour ce7.Select Command, conn)
adapter.Fill(ds)
Dim objPds As PagedDataSource = New PagedDataSource
objPds.DataSource = ds.Tables(0).DefaultView
objPds.AllowPaging = True
objPds.PageSize = 10
Dim CurPage As Integer
Dim LastPage As Integer
Dim DisplayPages As Integer
If Not (Request.QueryString("Page ") Is Nothing) Then
CurPage = Convert.ToInt32(Request.Qu eryString( "Page"))
Else
CurPage = 1
End If
objPds.CurrentPageIndex = CurPage - 1
LastPage = objPds.PageCount
DisplayPages = 5
lblCurrentPage.Text = "Page " + CurPage.ToString + " of " + LastPage.ToString()
Dim i As Integer
Dim intMod As Integer
Dim intDiv As Integer
For i = 0 To DisplayPages - 1
Dim lnk As New HyperLink
intDiv = Fix(CurPage \ DisplayPages)
intMod = CurPage Mod DisplayPages
If intMod + intDiv * DisplayPages + i <= LastPage Then
lnk.ID = "lnk" + (intMod + intDiv * DisplayPages + i).ToString()
lnk.Text = (intMod + intDiv * DisplayPages + i).ToString()
lnk.CssClass = "PropertyPageLink"
lnk.ToolTip = (intMod + intDiv * DisplayPages + i).ToString() + " of " + LastPage.ToString()
If intMod + intDiv * DisplayPages + i <> CurPage Then
lnk.NavigateUrl = Request.CurrentExecutionFi lePath + "?Page=" + Convert.ToString(intMod + intDiv * DisplayPages + i) + "&where='" + where + "'"
End If
plcPageNumbers.Controls.Ad d(lnk)
If intMod + intDiv * DisplayPages + i < LastPage Then
Dim lit As New Literal
lit.Text = " • "
plcPageNumbers.Controls.Ad d(lit)
End If
End If
Next
If intMod + intDiv * DisplayPages + i <= LastPage Then
lblPostPageNumbers.Visible = True
Else
lblPostPageNumbers.Visible = False
End If
If CurPage > DisplayPages Then
lblPrePageNumbers.Visible = True
End If
If Not objPds.IsFirstPage Then
lnkPrev.NavigateUrl = Request.CurrentExecutionFi lePath + "?Page=" + Convert.ToString(CurPage - 1) + "&where='" + where + "'"
lnkFirst.NavigateUrl = Request.CurrentExecutionFi lePath + "?Page=1&where='" + where + "'"
End If
If Not objPds.IsLastPage Then
lnkNext.NavigateUrl = Request.CurrentExecutionFi lePath + "?Page=" + Convert.ToString(CurPage + 1) + "&where='" + where + "'"
lnkLast.NavigateUrl = Request.CurrentExecutionFi lePath + "?Page=" + objPds.PageCount.ToString( ) + "&where='" + where + "'"
End If
ResultsList.DataSource = objPds
ResultsList.DataBind()
conn.Close()
Thanks!
Jennifer
<| << 1 2 3 4 5 >> |>
I've got it working except that the current page is ALWAYS the first page in the list. So, if I click on 5, 5 becomes the first item in the list. With the exception of Page 1 & 2, I'd like the first page in the list to be the third item. How do I do that?
Here's what I've got:
Dim conn As SqlConnection
Dim ds As New DataSet
Dim adapter As SqlDataAdapter
' Read the connection string from Web.config
Dim connectionString As String = ConfigurationManager.Conne
' Initialize connection
conn = New SqlConnection(connectionSt
'use a stored proc
'Not getting SQL Statement!
adapter = New SqlDataAdapter(SqlDataSour
adapter.Fill(ds)
Dim objPds As PagedDataSource = New PagedDataSource
objPds.DataSource = ds.Tables(0).DefaultView
objPds.AllowPaging = True
objPds.PageSize = 10
Dim CurPage As Integer
Dim LastPage As Integer
Dim DisplayPages As Integer
If Not (Request.QueryString("Page
CurPage = Convert.ToInt32(Request.Qu
Else
CurPage = 1
End If
objPds.CurrentPageIndex = CurPage - 1
LastPage = objPds.PageCount
DisplayPages = 5
lblCurrentPage.Text = "Page " + CurPage.ToString + " of " + LastPage.ToString()
Dim i As Integer
Dim intMod As Integer
Dim intDiv As Integer
For i = 0 To DisplayPages - 1
Dim lnk As New HyperLink
intDiv = Fix(CurPage \ DisplayPages)
intMod = CurPage Mod DisplayPages
If intMod + intDiv * DisplayPages + i <= LastPage Then
lnk.ID = "lnk" + (intMod + intDiv * DisplayPages + i).ToString()
lnk.Text = (intMod + intDiv * DisplayPages + i).ToString()
lnk.CssClass = "PropertyPageLink"
lnk.ToolTip = (intMod + intDiv * DisplayPages + i).ToString() + " of " + LastPage.ToString()
If intMod + intDiv * DisplayPages + i <> CurPage Then
lnk.NavigateUrl = Request.CurrentExecutionFi
End If
plcPageNumbers.Controls.Ad
If intMod + intDiv * DisplayPages + i < LastPage Then
Dim lit As New Literal
lit.Text = " • "
plcPageNumbers.Controls.Ad
End If
End If
Next
If intMod + intDiv * DisplayPages + i <= LastPage Then
lblPostPageNumbers.Visible
Else
lblPostPageNumbers.Visible
End If
If CurPage > DisplayPages Then
lblPrePageNumbers.Visible = True
End If
If Not objPds.IsFirstPage Then
lnkPrev.NavigateUrl = Request.CurrentExecutionFi
lnkFirst.NavigateUrl = Request.CurrentExecutionFi
End If
If Not objPds.IsLastPage Then
lnkNext.NavigateUrl = Request.CurrentExecutionFi
lnkLast.NavigateUrl = Request.CurrentExecutionFi
End If
ResultsList.DataSource = objPds
ResultsList.DataBind()
conn.Close()
Thanks!
Jennifer
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Computer101
EE Admin