View Single Post
  #2 (permalink)  
Old January 7th, 2011, 08:39 AM
Imar's Avatar
Imar Imar is offline
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Yes, you're correct. This is indeed a problem.
Quote:
I presume that there's a nice easy fix for this... some C# code for the dropdown On Select method to initialise the ListView, perhaps
And that's indeed the fix. For a detailed explanation, check out this post:

http://leedumond.com/blog/resetting-...in-a-listview/

The following should do the trick:

Code:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
  CommandEventArgs commandEventArgs = new CommandEventArgs("First", "");
  DataPager pager = ListView1.FindControl("DataPager1") as DataPager;
  if (pager != null)
  {
    NextPreviousPagerField nextPreviousPagerField = pager.Fields[0] as NextPreviousPagerField;
    if (nextPreviousPagerField != null)
    {
      nextPreviousPagerField.HandleEvent(commandEventArgs);
    }
  }
}
This also requires the following addition to the DropDownList in markup:

Code:
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="EntityDataSource1" DataTextField="Name" DataValueField="Id" onselectedindexchanged="DropDownList1_SelectedIndexChanged" />
For future posts like these, you're better off posting in the book's own forum category: http://p2p.wrox.com/book-beginning-asp-net-4-c-vb-560/

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote