![]() |
| |||||||
| Sponsored Links |
![]() | « Previous Thread | Next Thread » |
| | LinkBack | Thread Tools | Display Modes |
|
#1
| ||||
| ||||
| Morning ![]() ok i am busy with paging my datasource, currently I have previous and next button, it all works, b ut i want to modify it. Currently when you click on a button it redirects to the current page and puts the page number in a querystring, what I want to do is set a 'var' with the page number, and this works for the first time i click the next button, but when I click it again, it re-sets the 'var' so basically i can't get past page 2. how do i keep my var from being re-set, I want it to hold it's value at all times and allow it to be set with a new value? make sense? currently in my BOL i have a params class which will hold parameters. my params class: Code: Imports Microsoft.VisualBasic
Imports System
Imports System.ComponentModel
Imports System.Diagnostics
Namespace Keith.ProjectManager.BO
Public Class Params
'paging parameters
Private _activatedpage As Integer 'As Nullable(Of Integer)
Private _deactivatedpage As Integer 'As Nullable(Of Integer)
Private _orderby As String '= String.Empty
Private _activated As String '= String.Empty
Public Property ActivatedPage() As Integer
Get
Return _activatedpage
End Get
Set(ByVal value As Integer)
_activatedpage = value
End Set
End Property
Public Property DeactivatedPage() As Integer
Get
Return _deactivatedpage
End Get
Set(ByVal value As Integer)
_deactivatedpage = value
End Set
End Property
Public Property OrderBy() As String
Get
Return _orderby
End Get
Set(ByVal value As String)
_orderby = value
End Set
End Property
Public Property Activated() As String
Get
Return _activated
End Get
Set(ByVal value As String)
_activated = value
End Set
End Property
End Class
End Namespace
Code: Imports Keith.ProjectManager.BLL
Imports Keith.ProjectManager.BO
Imports System.Web.UI.WebControls
Imports System.Data
Imports System.Data.SqlClient
Partial Class view_projects
Inherits System.Web.UI.Page
Private CommandNames As String = String.Empty
Dim pagedData As New PagedDataSource()
'=============================================================================================
'handles page load events
Sub Page_Load()
'add textboxes that need to be cleared by onFocus
txtSvName.Attributes.Add("onFocus", "Clear(this)")
txtSvProjectNumber.Attributes.Add("onFocus", "Clear(this)")
txtSvDescription.Attributes.Add("onFocus", "Clear(this)")
System.Threading.Thread.Sleep("500")
'populate projectlist datasource
If Not IsPostBack Then
Dim myParams As Params = New Params
Populate_rpProjectList(myParams)
Populate_DeactivatedProjects(myParams)
End If
End Sub
'=============================================================================================
'populate and bind rpProjectList datasource
Sub Populate_rpProjectList(ByVal myParams As Params)
Dim ProjectsList As New ProjectsList
'ProjectsList = ProjectsManager.GetList(OrderBy, Activated)
pagedData.DataSource = ProjectsManager.GetList(myParams.OrderBy, myParams.Activated)
pagedData.AllowPaging = True
pagedData.PageSize = 1
Try
'pagedData.CurrentPageIndex = Int32.Parse(Request.QueryString("Page")).ToString()
pagedData.CurrentPageIndex = myParams.ActivatedPage
Catch ex As Exception
pagedData.CurrentPageIndex = 0
End Try
btnPrev.Visible = (Not pagedData.IsFirstPage)
btnNext.Visible = (Not pagedData.IsLastPage)
rpProjectList.DataSource = pagedData
rpProjectList.DataBind()
End Sub
Public Sub Prev_Click(ByVal obj As Object, ByVal e As EventArgs)
'Response.Redirect(Request.CurrentExecutionFilePath & "?Page=" & pagedData.CurrentPageIndex - 1)
Dim myParams As Params = New Params
myParams.ActivatedPage = pagedData.CurrentPageIndex - 1
Populate_rpProjectList(myParams)
End Sub
Public Sub Next_Click(ByVal obj As Object, ByVal e As EventArgs)
'Response.Redirect(Request.CurrentExecutionFilePath & "?Page=" & pagedData.CurrentPageIndex + 1)
Dim myParams As Params = New Params
myParams.ActivatedPage = pagedData.CurrentPageIndex + 1
Populate_rpProjectList(myParams)
End Sub
|
| Sponsored Links |
|
#2
| ||||
| ||||
| I tend to just use a hidden field on the page Code: <asp:hiddenfield id="_cur_page" runat="server" /> I don't believe variables set in your code behind are included in the viewstate so the value will be reset each time the page is loaded. There maybe another way, but that's the method I used... |
|
#3
| ||||
| ||||
| just tried to use session vars and still they get set back to zero?? how can this be? Shem |
|
#4
| ||||
| ||||
| Try using the same instance of myparams throughout the page. Rather than this:- Code: If Not IsPostBack Then
Dim myParams As Params = New Params
Populate_rpProjectList(myParams)
Populate_DeactivatedProjects(myParams)
End If
Code: Partial Class view_projects
Inherits System.Web.UI.Page
Private myparams as new Params
Private CommandNames As String = String.Empty
Dim pagedData As New PagedDataSource()
.
.
.
.
If Not IsPostBack Then
Populate_rpProjectList(myParams)
Populate_DeactivatedProjects(myParams)
End If
.
.
.
Public Sub Prev_Click(ByVal obj As Object, ByVal e As EventArgs)
myParams.ActivatedPage = pagedData.CurrentPageIndex - 1
Populate_rpProjectList(myParams)
End Sub
Public Sub Next_Click(ByVal obj As Object, ByVal e As EventArgs)
myParams.ActivatedPage = pagedData.CurrentPageIndex + 1
Populate_rpProjectList(myParams)
End Sub
|
| The Following User Says Thank You to richyrich For This Useful Post: | ||
Shem (July 21st, 2008) | ||
|
#5
| ||||
| ||||
| found the bugger giving me issues: Code: myParams.ActivatedPage = pagedData.CurrentPageIndex + 1 Code: myParams.ActivatedPage = myParams.ActivatedPage + 1 thanks for the help RR ![]() Shem |
| The Following User Says Thank You to Shem For This Useful Post: | ||
richyrich (July 21st, 2008) | ||
![]() |
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|