Need a little help with numeric links for paging Datalist.

siraero

Active member
Joined
Jan 21, 2012
Messages
32
Programming Experience
Beginner
Hi.

I have a little script that shows a
page with a Datalist.
it shows the datalist just fine and
paging with next, prev, last and first is also working fine.

Now im trying to add numeric link paging but
i cant get it to work/show.
Im new in this so somethings im
not 100% in.

I have a Public Function
called GetNumLink() and then i have a pageNumberLink.Text in a DoPaging Sub
thats = the GetNumLink()
and i have a Label called
pageNumberLink on my mainpage, but im not getting any numeric links in the
label.

hope someone can help me.
My Code_Behind is:
VB.NET:
Imports System.Data
Imports System.Data.OleDb

Partial Class gridview_EX_Default2
    Inherits System.Web.UI.Page

    Dim pagedData As New PagedDataSource

    Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        doPaging()
    End Sub

    Public Function getTheData() As DataTable
        'Get data from DB using DataSet  
        Using connection As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("MyConnStr").ConnectionString)
            Dim sql As String = "SELECT * FROM TableTest"
            Using adapter As OleDbDataAdapter = New OleDbDataAdapter(sql, connection)
                Dim ds As New DataSet()
                adapter.Fill(ds, "Portfolio_items")
                Return ds.Tables("Portfolio_items").Copy
            End Using
        End Using
    End Function

    Public Function getNumLink() As String
        pagedData.DataSource = getTheData().DefaultView
        Dim sbPager = New StringBuilder()
 Dim intLow As Integer = pagedData.CurrentPageIndex - 1
        Dim intHigh As Integer = pagedData.CurrentPageIndex + 3
        If intLow < 1 Then
            intLow = 1
        End If
        If intHigh > pagedData.PageCount Then
            intHigh = pagedData.PageCount
        End If
        If intHigh - intLow < 5 Then
            While (intHigh < intLow + 4) AndAlso intHigh < pagedData.PageCount
                intHigh += 1
            End While
        End If
        If intHigh - intLow < 5 Then
            While (intLow > intHigh - 4) AndAlso intLow > 1
                intLow -= 1
            End While
        End If
        For x As Integer = intLow To intHigh
            ' numeric links
            If x = pagedData.CurrentPageIndex + 1 Then
                sbPager.Append(x.ToString() & "  ")
            Else
                sbPager.Append("<a href=""")
                sbPager.Append(Request.CurrentExecutionFilePath)
                sbPager.Append("?Page=")
                sbPager.Append(x.ToString())
                sbPager.Append(""">")
                sbPager.Append(x.ToString())
                sbPager.Append("</a>  ")
            End If
        Next
    End Function

    Public Sub doPaging()
        pagedData.DataSource = getTheData().DefaultView
        pagedData.AllowPaging = True
        pagedData.PageSize = 5

        Try
            pagedData.CurrentPageIndex = Int32.Parse(Request.QueryString("Page")).ToString()
        Catch ex As Exception
            pagedData.CurrentPageIndex = 0
        End Try

        btnPrev.Visible = (Not pagedData.IsFirstPage)
        btnNext.Visible = (Not pagedData.IsLastPage)
        btnFirst.Visible = (Not pagedData.IsFirstPage)
        btnLast.Visible = (Not pagedData.IsLastPage)

        pageNumber.Text = (pagedData.CurrentPageIndex + 1) & " of " & pagedData.PageCount
        pageNumberLink.Text = getNumLink()

        theDataList.DataSource = pagedData
        theDataList.DataBind()
    End Sub




    Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnNext.Click
        Response.Redirect(Request.CurrentExecutionFilePath & "?Page=" & (pagedData.CurrentPageIndex + 1))
    End Sub

    Private Sub btnPrev_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnPrev.Click
        Response.Redirect(Request.CurrentExecutionFilePath & "?Page=" & (pagedData.CurrentPageIndex - 1))
    End Sub

    Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnLast.Click
        Response.Redirect(Request.CurrentExecutionFilePath & "?Page=" & (pagedData.PageCount - 1))
    End Sub

    Private Sub btnFirst_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnFirst.Click
        Response.Redirect(Request.CurrentExecutionFilePath & "?Page=" & (pagedData.CurrentPageIndex = 0))
    End Sub

End Class
 
Hello

Unless I am missing something, I assume you want to return sbPager. You dont seem to be returning anything in this function.

Regards
 
Back
Top