Go Back   DeveloperBarn Forums > Programming & Scripting > .Net Development

Sponsored Links

Discuss "Conflicts, UpdatePanel and PagedDataSource" in the .Net Development forum.

.Net Development - Learn about the Microsoft.Net framework and how to create powerful web-based (ASP.net) and client-based (Windows Forms) applications utilizing various languages such as C#, VB.Net, J# and others.


Reply « Previous Thread | Next Thread »
 
LinkBack Thread Tools Display Modes
  #1  
Old July 23rd, 2008, 04:33 AM
Shem's Avatar
Barn Enthusiast

 
Join Date: Mar 2008
Posts: 261
Thanks: 30
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default Conflicts, UpdatePanel and PagedDataSource

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
So I have to populate my datasource in every sub eg:
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
Conflict 2:
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
Reply With Quote
Sponsored Links
  #2  
Old July 23rd, 2008, 04:49 AM
Shem's Avatar
Barn Enthusiast

 
Join Date: Mar 2008
Posts: 261
Thanks: 30
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default

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
Reply With Quote
  #3  
Old July 23rd, 2008, 06:54 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

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)
Then in DrawPaging I had this line right at the beginning
Code:
pnlPagelinks.Controls.Clear()
which clears any controls that were built on Page_Load.

<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.
Reply With Quote
  #4  
Old July 23rd, 2008, 07:03 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

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
Then in Page_Load just have:-
Code:
BuildPagedData(0)
And on click event call:-
Code:
BuildPagedData(myPageButton.CommandArgument - 1)
Hope that makes sense.
Reply With Quote
  #5  
Old July 23rd, 2008, 07:07 AM
Shem's Avatar
Barn Enthusiast

 
Join Date: Mar 2008
Posts: 261
Thanks: 30
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default

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)
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
Shem
Reply With Quote
  #6  
Old July 23rd, 2008, 07:29 AM
Shem's Avatar
Barn Enthusiast

 
Join Date: Mar 2008
Posts: 261
Thanks: 30
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default

Quote:
Originally Posted by richyrich View Post
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
Then in Page_Load just have:-
Code:
BuildPagedData(0)
And on click event call:-
Code:
BuildPagedData(myPageButton.CommandArgument - 1)
Hope that makes sense.
only prob is I can't populate my datasource in Page_load, as my updatePanel
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
Reply With Quote
  #7  
Old July 23rd, 2008, 07:35 AM
jmurrayhead's Avatar
The Barnfather

 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 820
Thanks: 20
Thanked 74 Times in 71 Posts
Blog Entries: 5
Rep Power: 3
jmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura about

Awards Showcase
Microsoft SQL Server Microsoft Windows Microsoft .Net Classic ASP 
Total Awards: 4

Default

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
Reply With Quote
  #8  
Old July 23rd, 2008, 07:46 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

Quote:
Originally Posted by Shem View Post
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)
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
Shem
I'm a bit confused. You seem to be going round the houses to get the correct page from your PagedDataSource.

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?
Reply With Quote
  #9  
Old July 23rd, 2008, 07:48 AM
Shem's Avatar
Barn Enthusiast

 
Join Date: Mar 2008
Posts: 261
Thanks: 30
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default

Quote:
Originally Posted by jmurrayhead View Post
Instead of using a datasource, have you tried programmatically populating your controls?
I don't know what your talking about JMH, so no I haven't, I don't think
Reply With Quote
  #10  
Old July 23rd, 2008, 07:54 AM
jmurrayhead's Avatar
The Barnfather

 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 820
Thanks: 20
Thanked 74 Times in 71 Posts
Blog Entries: 5
Rep Power: 3
jmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura about

Awards Showcase
Microsoft SQL Server Microsoft Windows Microsoft .Net Classic ASP 
Total Awards: 4

Default

Quote:
Originally Posted by Shem View Post
I don't know what your talking about JMH, so no I haven't, I don't think
What I'm saying is that you don't have to use the ObjectDataSource or SqlDataSource. You mentioned that the UpdatePanel might be causing a problem with populating your datasource on postback. So why not try using a DataReader and set the datasource of the Repeater to the DataReader?

Code:
Repeater1.DataSource = dtr
Repeater1.DataBind()
Reply With Quote
Reply

  DeveloperBarn Forums > Programming & Scripting > .Net Development

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
2nd UpdatePanel won't update Shem .Net Development 19 July 10th, 2008 09:48 AM


All times are GMT -4. The time now is 07:51 PM.



Content Relevant URLs by vBSEO 3.2.0