?
Solved

Listview datapager control problem

Posted on 2009-04-21
6
Medium Priority
?
1,512 Views
Last Modified: 2012-06-21
hi all,
i have a listview, and a datapager control.I'm trying to implement paging for this listview. but i'm going wrong somewhere.Please help me solve this paging problem.

I'm using stored procedure to populate the listview. When edited or inserted a new record, i update a hidden field  value ,of the status of the listview, if it has been updated or the old records still persist.
Depending on this hiddenfield status, i set the datasource of the listview.

When i set the databind in the pre render event of the datapager control, i get error:
"The control collection cannot be modified during DataBind, Init, Load, PreRender or Unload phases".
Why is that happening and how to solve it.
below is the brief code

Protected Sub orderDataPager_PreRender(ByVal sender As Object, ByVal e As EventArgs)
        If HDNOrderStatus.Value = "Updated" Then
            ListOrderForecast.DataSource = Session("UpdatedOrderForecast")
        ElseIf HDNOrderStatus.Value = "New" Then
            ListOrderForecast.DataSource = Session("OrderForecast")
        End If
 
        ListOrderForecast.DataBind()
 
    End Sub
 
' This is the datapager in layout template
<asp:DataPager ID="orderDataPager" runat="server" PageSize="5" PagedControlID="ListOrderForecast" OnPreRender="orderDataPager_PreRender">
                        <Fields>
                            <asp:NumericPagerField ButtonCount="5" NextPageText="..." 
                PreviousPageText="..."  />
                        </Fields>
                    </asp:DataPager>

Open in new window

0
Comment
Question by:SaraDob
  • 3
  • 2
6 Comments
 
LVL 1

Author Comment

by:SaraDob
ID: 24195952
Anyone please help me....
0
 
LVL 15

Expert Comment

by:NazoUK
ID: 24202724
I think the problem is that by the datapager_prerender event the controls for the datapager have already been created but calling databind on its associated datacontrol would require the controls to be recreated which it can't do at this stage in the lifecycle.

I don't really understand what you're trying to do but you try doing it at a different stage in the life cycle such as Page_Load
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24204181
Use the pageload event as suggested and enclose the code in
If Not Page.IsPostBack Then
   'code
End If
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Author Comment

by:SaraDob
ID: 24209262
hi
i'm not able to understand this datapager control at all. i read an article and followed it.
As i'm newbie, can you please elborate , the way i have to test it.
thanks for your replies
 
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 1000 total points
ID: 24209292
Move this code from prerender to page load
        If HDNOrderStatus.Value = "Updated" Then
            ListOrderForecast.DataSource = Session("UpdatedOrderForecast")
        ElseIf HDNOrderStatus.Value = "New" Then
            ListOrderForecast.DataSource = Session("OrderForecast")
        End If
 
        ListOrderForecast.DataBind()

Write the following code in page load event
     
        If HDNOrderStatus.Value = "Updated" Then
            ListOrderForecast.DataSource = Session("UpdatedOrderForecast")
        ElseIf HDNOrderStatus.Value = "New" Then
            ListOrderForecast.DataSource = Session("OrderForecast")
        End If
 
        ListOrderForecast.DataBind()

Open in new window

0
 
LVL 1

Author Closing Comment

by:SaraDob
ID: 31572797
thanks a lot
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month17 days, 13 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question