![]() |
| |||||||
| Sponsored Links |
![]() | « Previous Thread | Next Thread » |
| | LinkBack | Thread Tools | Display Modes |
|
#1
| ||||
| ||||
| I have 2 conflicting functionalitys on one of my pages, which will eventually be on all my pages ![]() Conflict One: My page uses and UpdatePanel, I cannot populate my datasource on postback as my update panel doesn't work. Code: 'populate projectlist datasource
If Not IsPostBack Then
Populate_rpProjectList(myParams)
Populate_DeactivatedProjects(myParams)
End If
Code: 'put code in here that needs to be run on the btnSave event
Protected Sub btnSave_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
'populate Projects and save new data
Dim myProjects As Projects = New Projects
myProjects.Name = txtSvName.Text
myProjects.ProjectNumber = txtSvProjectNumber.Text
myProjects.Description = txtSvDescription.Text
myProjects.TheDate = Now()
myProjects.EditedDate = Now()
myProjects.UserID = HttpContext.Current.Session("UserID")
myProjects.EditedID = 0
myProjects.Activated = "true"
myProjects.Idkey = 0
ProjectsManager.Save(myProjects)
'bind the datasource to repeater to show updated results
Populate_rpProjectList(myParams)
're-set the textboxes
txtSvName.Text = "Name"
txtSvProjectNumber.Text = "Project No"
txtSvDescription.Text = "Description"
End Sub
'this handles the sorting functionality for rpProjectList datasource
Sub editSortbuttons_OnClick(ByVal s As Object, ByVal e As EventArgs)
Dim mybutton As LinkButton = s
Dim sortby As String = mybutton.CommandArgument
Dim sortwhat As String = mybutton.CommandName
Select Case sortwhat
Case "name"
If sortby = "desc" Then
lbtnEditName.CommandArgument = "asc"
myParams.OrderBy = "name DESC"
End If
If sortby = "asc" Then
lbtnEditName.CommandArgument = "desc"
myParams.OrderBy = "name ASC"
End If
Case "number"
If sortby = "desc" Then
lbtnEditProjNo.CommandArgument = "asc"
myParams.OrderBy = "number DESC"
End If
If sortby = "asc" Then
lbtnEditProjNo.CommandArgument = "desc"
myParams.OrderBy = "number ASC"
End If
Case "description"
If sortby = "desc" Then
lbtnEditDescription.CommandArgument = "asc"
myParams.OrderBy = "description DESC"
End If
If sortby = "asc" Then
lbtnEditDescription.CommandArgument = "desc"
myParams.OrderBy = "description ASC"
End If
Case "created"
If sortby = "desc" Then
lbtnEditCreated.CommandArgument = "asc"
myParams.OrderBy = "pdate DESC"
End If
If sortby = "asc" Then
lbtnEditCreated.CommandArgument = "desc"
myParams.OrderBy = "pdate ASC"
End If
Case "edited"
If sortby = "desc" Then
lbtnEditEdited.CommandArgument = "asc"
myParams.OrderBy = "eDate DESC"
End If
If sortby = "asc" Then
lbtnEditEdited.CommandArgument = "desc"
myParams.OrderBy = "eDate ASC"
End If
End Select
'bind the datasource to repeater to show updated results
Populate_rpProjectList(myParams)
End Sub
I want to have paging for each datasource that needs it, and most of my pages will have more than one datasource that needs paging. now the problem with my paged data links is that they need to be renendered on every postback, but they rely on the datasource to get the correct PagedDataSource details to display, else they only display once. and seeing as my datasource only populates in Page_load on the first time the page is loaded, my paged data links only show once. ![]() and yes i do need to dynamically add links as I make use of pagenumbers as links. Hopefully that all made sense. Does anyone see a solution to this, I have tried many things but nothing works yet ![]() Shem Last edited by richyrich; July 23rd, 2008 at 07:49 AM. Reason: Changed Title Slightly |
| Sponsored Links |
|
#2
| ||||
| ||||
| I think I have a solution... the reason my paged data links need to be called after populating my datasource is because it needs the pageNumber and pageCount that is set everytime the datasource is populated. All i need to do is create a sub to capture the values everytime my datasource is populated, and put this sub in the page_load, or something along that line. though come to think of it, page_load fires before anything else right, so I would be back where i started? Shem |
|
#3
| ||||
| ||||
| OK..This is what I have so far...Your Page_Load should be as is, I think... Then in your On Click event you basically need to completely rebuild the PagedDataSource again and then set the CurrentPageIndex to PageNumber - 1 (as it uses an index) Remember to rebuild the whole lot again.. Code: PagedData.AllowPaging = True PagedData.DataSource = ...... PagedData.CurrentPageIndex = PageNumber - 1 PagedData.PageSize = 10 repeater1.datasource = PagedData repeater1.databind() DrawPaging(PagedData.CurrentPageIndex + 1, PagedData.PageCount) Code: pnlPagelinks.Controls.Clear() <edit>I guess the easiest way to do it, would be to build a sub, which accepts PageNumber and PageCount properties, that just builds the PagedDataSource, populates the repeater with the new data and then rebuilds the buttons. Then just call this from Page_Load or from the Button Click event.</edit> Last edited by richyrich; July 23rd, 2008 at 06:56 AM. |
|
#4
| ||||
| ||||
| Something like this should do the trick:- Code: Sub BuildPagedData(PageIndex) Dim PagedData As New PagedDataSource PagedData.AllowPaging = True 'or you could pass a value to the sub for this. Then you could have a view all button. If not set to True, you get all records PagedData.DataSource = ....whatever your datasource is PagedData.CurrentPageIndex = PageIndex PagedData.PageSize = 10 'or you could have a value passed to the sub to set this your_repeater.DataSource = PagedData your_repeater.DataBind() DrawPaging(PagedData.CurrentPageIndex + 1, PagedData.PageCount) ' or have the draw paging code in here. End Sub Code: BuildPagedData(0) Code: BuildPagedData(myPageButton.CommandArgument - 1) |
|
#5
| ||||
| ||||
| RR, i have my datasource in a sub, if i call that sub at the end of my OnClick then it should do the same thing your saying by re-creating the whole paged datasource? OnClick Event: Code: Sub lblPageLinks_OnClick(ByVal s As Object, ByVal e As EventArgs)
Dim myPageButton As LinkButton = s
Dim pagenumber As String = myPageButton.CommandArgument
Dim pagebuttoname As String = myPageButton.CommandName
Select Case pagebuttoname
Case "Prev10"
myParams.ActivatedPage = pagenumber
Case "Next10"
myParams.ActivatedPage = pagenumber
Case "Prev"
myParams.ActivatedPage = pagenumber
Case "Next"
myParams.ActivatedPage = pagenumber
Case "PageNumber"
myParams.ActivatedPage = pagenumber
End Select
Populate_rpProjectList(myParams)
Code: Sub Populate_rpProjectList(ByVal myParams As ProjectsParams)
Dim ProjectsList As New ProjectsList
pagedData.DataSource = ProjectsManager.GetList(myParams.OrderBy, myParams.Activated)
pagedData.AllowPaging = True
pagedData.PageSize = 5
Try
pagedData.CurrentPageIndex = myParams.ActivatedPage
Catch ex As Exception
pagedData.CurrentPageIndex = 0
End Try
rpProjectList.DataSource = pagedData
rpProjectList.DataBind()
End Sub
|
|
#6
| ||||
| ||||
| Quote:
doesn't seem to update when i do that, I always have to refresh to get the updated data, hence me populating my datasource inside the relevant subs that need to update my datasource, and as you now know, the DrawPaging sub needs to feed off of the datasource and HAS TO BE called in PAge_load which is where my conflict comes in. For some reason my update panel won't update if the datasource is populated in Page_load? maybe this is wrong, maybe all fault lies there? Shem |
|
#7
| ||||
| ||||
| Instead of using a datasource, have you tried programmatically populating your controls?
__________________ 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 |
|
#8
| ||||
| ||||
| Quote:
How is myParams.ActivatedPage being set? Personally I would scrap passing the current page back and forth between the BOL and the Presentation Layer. You already have this value set in your OnClick, so you just pass it to your BuildPagedData sub. As I understand it, the PagedDataSource is just a wrapper you put round a normal datasource. It then divides the datasource up into pages based on how many you want to display on each page. You just tell it which page you want to display using the CurrentPageIndex In theory I don't see why your DataSource Sub shouldn't work. Also, have you noticed that each Case in your OnClick sub is doing exactly the same thing irrespective of which button was clicked? |
|
#9
| ||||
| ||||
| Quote:
|
|
#10
| ||||
| ||||
| Quote:
Code: Repeater1.DataSource = dtr Repeater1.DataBind() |
![]() |
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| 2nd UpdatePanel won't update | Shem | .Net Development | 19 | July 10th, 2008 09:48 AM |