DropDownList has a AutoPostback True set and on SelectedIndexChanged event i am calling again this function FillRecords
Now the issue is Default
All will be selected in the list then i selected 10 from the list and go to the 2nd page of the listview control and then again i selected 15 from the list then in the ListView 1st Page is default selected in the pager and then i again selected 10 from
the list now i listview showing me the 2nd page my question why its here not showing me the 1st page ?
Rick Jackson (Please mark as answer if my post help you to solve your issue) [Happy programming]
But in the future if that link is dead here is the function we need to call if any dropdownlist has DropDownlist ==> Total Number of Rows ==> ALL, 10, 15, 20
privatevoidResetListViewPager() { DataPager pager =(DataPager)ListViewMembers.FindControl("DataPager1"); if(pager !=null) { CommandEventArgs commandEventArgs =newCommandEventArgs(DataControlCommands.FirstPageCommandArgument,""); // MAKE SURE THE INDEX IN THE NEXT LINE CORRESPONDS TO THE CORRECT FIELD IN YOUR PAGER NextPreviousPagerField nextPreviousPagerField = pager.Fields[0]asNextPreviousPagerField; if(nextPreviousPagerField !=null) { nextPreviousPagerField.HandleEvent(commandEventArgs); }
// THIS COMMENTED-OUT SECTION IS HOW IT WOULD BE DONE IF USING A NUMERIC PAGER RATHER THAN A NEXT/PREVIOUS PAGER //commandEventArgs = new CommandEventArgs("0", ""); //NumericPagerField numericPagerField = pager.Fields[0] as NumericPagerField; //if (numericPagerField != null) //{ // numericPagerField.HandleEvent(commandEventArgs); //} } }
Irfaan
Member
52 Points
6 Posts
Re: Problem with DataPager
Nov 11, 2009 09:12 AM|LINK
Thanks Melbu. It worked for me.
rickjackson
Participant
1362 Points
405 Posts
Re: Problem with DataPager
Mar 10, 2010 05:57 PM|LINK
Hey sabbirspide i gone through your solution its working nicely.
I have DropDownlist ==> Total Number of Rows ==> ALL, 10, 15, 20
I am setting the PageSize property of the DataPagerControl
private void FillRecords() { List<EmployeeInfo> objEmployeeInfo = new List<EmployeeInfo>(); objEmployeeInfo = EmployeeInfoMethods.iGetEmployeeInfoList(); if (ddlTotalRecords.SelectedValue == "0") { DataPager1.PageSize = objEmployeeInfo.Count; } else if (ddlTotalRecords.SelectedValue == "10") { DataPager1.PageSize = Convert.ToInt32(ddlTotalRecords.SelectedValue); } else if (ddlTotalRecords.SelectedValue == "15") { DataPager1.PageSize = Convert.ToInt32(ddlTotalRecords.SelectedValue); } else if (ddlTotalRecords.SelectedValue == "20") { DataPager1.PageSize = Convert.ToInt32(ddlTotalRecords.SelectedValue); } LstGridView.DataSource = objEmployeeInfo; LstGridView.DataBind(); }DropDownList has a AutoPostback True set and on SelectedIndexChanged event i am calling again this function FillRecords
Now the issue is Default All will be selected in the list then i selected 10 from the list and go to the 2nd page of the listview control and then again i selected 15 from the list then in the ListView 1st Page is default selected in the pager and then i again selected 10 from the list now i listview showing me the 2nd page my question why its here not showing me the 1st page ?
rickjackson
Participant
1362 Points
405 Posts
Re: Problem with DataPager
Mar 10, 2010 06:20 PM|LINK
i have found the answer of my question we need to reset the pager in DataPager control. Here is the link : http://stackoverflow.com/questions/234289/listview-with-datapager-not-working
But in the future if that link is dead here is the function we need to call if any dropdownlist has DropDownlist ==> Total Number of Rows ==> ALL, 10, 15, 20
We need to call this function
protected void ddlTotalRecords_SelectedIndexChanged(object sender, EventArgs e) { try { FillRecords(); ResetListViewPager(); } catch (Exception ex) { throw ex; } }mustafaiqbal
Member
4 Points
2 Posts
Re: Problem with DataPager
Nov 12, 2012 04:29 AM|LINK
Its Simple, Just Get "ID" in "QUERY-STRING" from the Database, Now Set it to the Pager Control Property as [ QueryStringField="ID" ] like:
<asp:DataPager ID="DataPagerProducts" runat="server" QueryStringField="ID" PageSize="3"> <Fields> <asp:NextPreviousPagerField ShowFirstPageButton="True" ShowNextPageButton="False" /> <asp:NumericPagerField /> <asp:NextPreviousPagerField ShowLastPageButton="True" ShowPreviousPageButton="False" /> </Fields> </asp:DataPager>Note: if not woking, then set also [ PagedControlID="ListView_Name" ].
Regards,
Mustafa Iqbal.
DataPager Problem