MrPink1138
Programmer
I'm an old school ASP guru trying to make the switch to ASP.NET and need some help with what is probably a pretty simple question.
I'm using a repeater element connected to a database to display a list. I'm trying to add some paging controls to it so it only shows a few records at a time. I want to have a CurrentPage variable to store which page the user is on and increment accordingly when the user clicks a button. The first time the page loads it would also need to be initialized to 1.
I've tried using a public variable and i've tried using the ViewState but can't seem to get it working right. If someone could point me in the right direction I would be grateful.
My code so far is below:
I'm using a repeater element connected to a database to display a list. I'm trying to add some paging controls to it so it only shows a few records at a time. I want to have a CurrentPage variable to store which page the user is on and increment accordingly when the user clicks a button. The first time the page loads it would also need to be initialized to 1.
I've tried using a public variable and i've tried using the ViewState but can't seem to get it working right. If someone could point me in the right direction I would be grateful.
My code so far is below:
Code:
Public CurrentPage As Integer
Sub PageLoad()
ItemsGet()
End Sub
Sub ItemsGet()
Dim strConnection As String
Dim oConn As SqlConnection
Dim ds As DataSet
Dim oRS As SqlDataAdapter
Dim oPds As PagedDataSource
ds = New DataSet()
strConnection = ConfigurationSettings.AppSettings("ConnectionString")
oConn = New SqlConnection (strConnection)
oRS = New SqlDataAdapter("spGetContractsAll", oConn)
oRS.Fill (ds, "results")
oPds = New PagedDataSource()
oPds.DataSource = ds.Tables("results").DefaultView
oPds.AllowPaging = true
oPds.PageSize = 3
oPds.CurrentPageIndex = CurrentPage
cmdPrev.Enabled = NOT oPds.IsFirstPage
cmdNext.Enabled = NOT oPds.IsLastPage
rptContracts.DataSource = oPds
rptContracts.DataBind()
End Sub
Sub cmdPrev_Click(s As Object, e As System.EventArgs)
CurrentPage -= 1
ItemsGet()
End Sub
Sub cmdNext_Click(s As Object, e As System.EventArgs)
CurrentPage += 1
ItemsGet()
End Sub