You have to move to first page after the search record, because lets take one example you have a total 25 record and you have 10record per page, that means tou have 3 page in list view.
Now you are searching some date and that will return 8 records, and you are standing on second page, so data is not available for second page and it will display blank
if you moved to first page programetically data will be displayed, check below code for move to first page programetically
if (IsPostBack)
{
DataPager pgr = MyListView.FindControl("MyPager") as DataPager;
if (pgr != null && MyListView.Items.Count != pgr.TotalRowCount)
{
pgr.SetPageProperties(0, pgr.MaximumRows, false);
}
}
let me know if any query
Thanks,
Gaurav Dhol
Skype ID : dhol.gaurav
If My Post contains helped you, Please Mark as Answer
Thanks for your help. I tried you changes in my PagePropertieschanging event. I now get my results when I click find. However, during the initial load, It has stopped paging. When I click "Next" it does not do anything.
I tried you changes in my PagePropertieschanging event. I now get my results when I click find. However, during the initial load, It has stopped paging. When I click "Next" it does not do anything.
After you use the DataPager.SetPageProperties method to set the page-related properties in the DataPager control, please don't forget to invoke the BindFundNoTable() method. In order to paging in the initial load, please modify your code as follows:
Thanks for your help, but it is still not paging. I load the webpage and from the very start when I clcik "Next" it does not move..
In order to resolve your issue, please try to simply your project and upload it to skydrive. Then provide the link. I want to test locally and try to resolve it.
Best wishes,
Please mark the replies as answers if they help or unmark if not.
Feedback to us
I have included my Web Project and the AdventureWorks DB that I modified. Hopefully I simplified this enough.
My goal is to:
Open the web site ~Admin\ ManageFundsTBL.aspx
Able to page back and forth.
Do a Search on location ID using the text box
Edit the searched item.
Note: No need to page back when I have found the item. I will have a refresh button that will refresh the entire list view. Also the webconfig needs to be modified with your own credentials.
caolong
Member
5 Points
31 Posts
Asp.net paging and search function not working
Oct 08, 2012 09:58 PM|LINK
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.Security; using System.Drawing; using System.Data.SqlClient; using System.Configuration; using System.Data; public partial class Controls_ManageFundsControl : System.Web.UI.UserControl { private void BindFundNoTable() { ListView ManageFundNoListView = this.FindControl("ManageFundsListView") as ListView; TextBox FindFundNoTextBox = ManageFundNoListView.FindControl("FindFundNoTextBox") as TextBox; //ManageFundNoListView.DataSourceID = null; SqlConnection HighlanderVMconn = new SqlConnection(ConfigurationManager.ConnectionStrings["HighlanderVMconn"].ConnectionString); HighlanderVMconn.Open(); SqlCommand cmdExecFindALLFundNoSP = new SqlCommand("DisplayALLFundsSP", HighlanderVMconn); cmdExecFindALLFundNoSP.CommandType = CommandType.StoredProcedure; SqlDataAdapter da = new SqlDataAdapter(cmdExecFindALLFundNoSP); DataSet ds = new DataSet(); da.Fill(ds, "DisplayALLFundNotable"); ManageFundNoListView.DataSource = ds.Tables["DisplayALLFundNotable"]; ManageFundNoListView.DataBind(); HighlanderVMconn.Close(); } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindFundNoTable(); } } protected void FindFundNoButton_OnClick(object sender, EventArgs e) { if (!Page.IsValid) { return; } ListView ManageFundNoListView = this.FindControl("ManageFundsListView") as ListView; TextBox FindFundNoTextBox = ManageFundNoListView.FindControl("FindFundNoTextBox") as TextBox; if (FindFundNoTextBox != null && ManageFundNoListView != null) { //Makes SQl connection SqlConnection HighlanderVMconn = new SqlConnection(ConfigurationManager.ConnectionStrings["HighlanderVMconn"].ConnectionString); HighlanderVMconn.Open(); SqlCommand cmdExecFindFundNoSP = new SqlCommand("FindFundsSP", HighlanderVMconn); cmdExecFindFundNoSP.CommandType = CommandType.StoredProcedure; cmdExecFindFundNoSP.Parameters.AddWithValue("@FundNo", FindFundNoTextBox.Text); SqlDataAdapter da = new SqlDataAdapter(cmdExecFindFundNoSP); DataSet ds = new DataSet(); da.Fill(ds, "FindFundNotable"); ManageFundNoListView.DataSource = ds.Tables["FindFundNotable"]; ManageFundNoListView.DataBind(); HighlanderVMconn.Close(); } } protected void ListViewItemEditing(object sender, ListViewEditEventArgs e) { ListView ManageFundNoListView = this.FindControl("ManageFundsListView") as ListView; TextBox FindFundNoTextBox = ManageFundNoListView.FindControl("FindFundNoTextBox") as TextBox; ManageFundNoListView.EditIndex = e.NewEditIndex; BindFundNoTable(); } protected void ListViewItemUpdating(object sender, ListViewUpdateEventArgs e) { ListView ManageFundNoListView = this.FindControl("ManageFundsListView") as ListView; TextBox FindFundNoTextBox = ManageFundNoListView.FindControl("FindFundNoTextBox") as TextBox; ListViewItem item = ManageFundNoListView.Items[e.ItemIndex]; TextBox DistIDTextBox = (TextBox)item.FindControl("DistIDTextBox"); // ManageFundNoListView.DataSourceID = null; string FundNo = ManageFundNoListView.DataKeys[e.ItemIndex].Value.ToString(); SqlConnection HighlanderVMconn = new SqlConnection(ConfigurationManager.ConnectionStrings["HighlanderVMconn"].ConnectionString); HighlanderVMconn.Open(); SqlCommand cmdExecUpdateFundNoSP = new SqlCommand("UpdateFundsSP", HighlanderVMconn); cmdExecUpdateFundNoSP.CommandType = CommandType.StoredProcedure; cmdExecUpdateFundNoSP.Parameters.AddWithValue("@FundNo", FundNo); cmdExecUpdateFundNoSP.Parameters.AddWithValue("@DistId", DistIDTextBox.Text); cmdExecUpdateFundNoSP.ExecuteNonQuery(); ManageFundNoListView.EditIndex = -1; BindFundNoTable(); } protected void ListViewItemCanceling(object sender, ListViewCancelEventArgs e) { ListView ManageFundNoListView = this.FindControl("ManageFundsListView") as ListView; TextBox FindFundNoTextBox = ManageFundNoListView.FindControl("FindFundNoTextBox") as TextBox; ManageFundNoListView.EditIndex = -1; BindFundNoTable(); } protected void InsertListViewItem(object sender, ListViewInsertEventArgs e) { ListView ManageFundNoListView = this.FindControl("ManageFundsListView") as ListView; TextBox FindFundNoTextBox = ManageFundNoListView.FindControl("FindFundNoTextBox") as TextBox; // ManageFundNoListView.DataSourceID = null; ListViewItem item = e.Item; TextBox FundNoTextBox = (TextBox)item.FindControl("FundNoTextBox"); TextBox DistIDTextBox = (TextBox)item.FindControl("DistIDTextBox"); SqlConnection HighlanderVMconn = new SqlConnection(ConfigurationManager.ConnectionStrings["HighlanderVMconn"].ConnectionString); HighlanderVMconn.Open(); SqlCommand cmdExecInsertFundNoSP = new SqlCommand("InsertFundsSP", HighlanderVMconn); cmdExecInsertFundNoSP.CommandType = CommandType.StoredProcedure; cmdExecInsertFundNoSP.Parameters.AddWithValue("@FundNo", FundNoTextBox.Text); cmdExecInsertFundNoSP.Parameters.AddWithValue("@DistId", DistIDTextBox.Text); cmdExecInsertFundNoSP.ExecuteNonQuery(); BindFundNoTable(); } protected void ListViewDeleteItem(object sender, ListViewDeleteEventArgs e) { ListView ManageFundNoListView = this.FindControl("ManageFundsListView") as ListView; TextBox FindFundNoTextBox = ManageFundNoListView.FindControl("FindFundNoTextBox") as TextBox; ListViewItem item = ManageFundNoListView.Items[e.ItemIndex]; // ManageFundNoListView.DataSourceID = null; string FundNo = ManageFundNoListView.DataKeys[e.ItemIndex].Value.ToString(); SqlConnection HighlanderVMconn = new SqlConnection(ConfigurationManager.ConnectionStrings["HighlanderVMconn"].ConnectionString); HighlanderVMconn.Open(); SqlCommand cmdExecDeleteFundsSP = new SqlCommand("DeleteFundsSP", HighlanderVMconn); cmdExecDeleteFundsSP.CommandType = CommandType.StoredProcedure; cmdExecDeleteFundsSP.Parameters.AddWithValue("@FundNo", FundNo); cmdExecDeleteFundsSP.ExecuteNonQuery(); HighlanderVMconn.Close(); //ManageFundNoListView.DataSourceID = "ManageFundsSqlDataSource"; FindFundNoTextBox.Text = "Search FundNo."; BindFundNoTable(); } protected void PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e) { ListView ManageFundNoListView = this.FindControl("ManageFundsListView") as ListView; TextBox FindFundNoTextBox = ManageFundNoListView.FindControl("FindFundNoTextBox") as TextBox; DataPager pager = (DataPager)((ListView)sender).FindControl("DataPager1"); pager.SetPageProperties(e.StartRowIndex, e.MaximumRows, false); BindFundNoTable(); } //*****************************************Custom Validators************************************************* protected void FindFundNoMessageCustomValidator_ServerValidate(object source, ServerValidateEventArgs args) { ListView ManageFundNoListView = this.FindControl("ManageFundsListView") as ListView; TextBox FindFundNoTextBox = ManageFundNoListView.FindControl("FindFundNoTextBox") as TextBox; ManageFundNoListView.EditIndex = -1; //Makes SQl connection SqlConnection HighlanderVMconn = new SqlConnection(ConfigurationManager.ConnectionStrings["HighlanderVMconn"].ConnectionString); HighlanderVMconn.Open(); SqlCommand cmdExecCheckFundsExistsSP = new SqlCommand("CheckFundsExistsSP", HighlanderVMconn); cmdExecCheckFundsExistsSP.CommandType = CommandType.StoredProcedure; cmdExecCheckFundsExistsSP.Parameters.AddWithValue("@FundNo", FindFundNoTextBox.Text); cmdExecCheckFundsExistsSP.CommandType = CommandType.StoredProcedure; int ResultsCount = Convert.ToInt32(cmdExecCheckFundsExistsSP.ExecuteScalar().ToString()); if (ResultsCount == 0) { args.IsValid = false; } HighlanderVMconn.Close(); } protected void FindFundNoDupMessageCustomValidator_ServerValidate(object source, ServerValidateEventArgs args) { ListView ManageFundNoListView = this.FindControl("ManageFundsListView") as ListView; TextBox FundNoTextBox = ManageFundNoListView.InsertItem.FindControl("FundNoTextBox") as TextBox; ManageFundNoListView.EditIndex = -1; //Makes SQl connection SqlConnection HighlanderVMconn = new SqlConnection(ConfigurationManager.ConnectionStrings["HighlanderVMconn"].ConnectionString); HighlanderVMconn.Open(); SqlCommand cmdExecCheckFundsExistsSP = new SqlCommand("CheckFundsExistsSP", HighlanderVMconn); cmdExecCheckFundsExistsSP.CommandType = CommandType.StoredProcedure; cmdExecCheckFundsExistsSP.Parameters.AddWithValue("@FundNo", FundNoTextBox.Text); cmdExecCheckFundsExistsSP.CommandType = CommandType.StoredProcedure; int ResultsCount = Convert.ToInt32(cmdExecCheckFundsExistsSP.ExecuteScalar().ToString()); if (ResultsCount != 0) { args.IsValid = false; } HighlanderVMconn.Close(); } } //*****************************************Custom Validators End*************************************************dhol.gaurav
Contributor
3998 Points
725 Posts
Re: Asp.net paging and search function not working
Oct 09, 2012 09:47 AM|LINK
Hey,
You have to move to first page after the search record, because lets take one example you have a total 25 record and you have 10record per page, that means tou have 3 page in list view.
Now you are searching some date and that will return 8 records, and you are standing on second page, so data is not available for second page and it will display blank
if you moved to first page programetically data will be displayed, check below code for move to first page programetically
if (IsPostBack) { DataPager pgr = MyListView.FindControl("MyPager") as DataPager; if (pgr != null && MyListView.Items.Count != pgr.TotalRowCount) { pgr.SetPageProperties(0, pgr.MaximumRows, false); } }let me know if any query
Gaurav Dhol
Skype ID : dhol.gaurav
If My Post contains helped you, Please Mark as Answer
caolong
Member
5 Points
31 Posts
Re: Asp.net paging and search function not working
Oct 09, 2012 03:26 PM|LINK
Hi,
Thanks for your help. I tried you changes in my PagePropertieschanging event. I now get my results when I click find. However, during the initial load, It has stopped paging. When I click "Next" it does not do anything.
protected void PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e) { ListView ManageFundNoListView = this.FindControl("ManageFundsListView") as ListView; TextBox FindFundNoTextBox = ManageFundNoListView.FindControl("FindFundNoTextBox") as TextBox; //DataPager pager = (DataPager)((ListView)sender).FindControl("DataPager1"); //pager.SetPageProperties(e.StartRowIndex, e.MaximumRows, false); //BindFundNoTable(); if (IsPostBack) { DataPager pgr = ManageFundNoListView.FindControl("DataPager1") as DataPager; if (pgr != null && ManageFundNoListView.Items.Count != pgr.TotalRowCount) { pgr.SetPageProperties(0, pgr.MaximumRows, false); } } }Catherine Sh...
All-Star
23382 Points
2490 Posts
Microsoft
Re: Asp.net paging and search function not working
Oct 15, 2012 06:26 AM|LINK
Hi,
After you use the DataPager.SetPageProperties method to set the page-related properties in the DataPager control, please don't forget to invoke the BindFundNoTable() method. In order to paging in the initial load, please modify your code as follows:
protected void PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e) { ListView ManageFundNoListView = this.FindControl("ManageFundsListView") as ListView; TextBox FindFundNoTextBox = ManageFundNoListView.FindControl("FindFundNoTextBox") as TextBox; if (IsPostBack) { DataPager pgr = ManageFundNoListView.FindControl("DataPager1") as DataPager; if (pgr != null && ManageFundNoListView.Items.Count != pgr.TotalRowCount) { pgr.SetPageProperties(0, pgr.MaximumRows, false); BindFundNoTable(); } else { DataPager pager = (DataPager)((ListView)sender).FindControl("DataPager1"); pager.SetPageProperties(e.StartRowIndex, e.MaximumRows, false); BindFundNoTable(); } } }Best wishes,
Feedback to us
Develop and promote your apps in Windows Store
caolong
Member
5 Points
31 Posts
Re: Asp.net paging and search function not working
Oct 15, 2012 03:56 PM|LINK
Thanks for your help, but it is still not paging. I load the webpage and from the very start when I clcik "Next" it does not move..
protected void PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e) { ListView ManageFundNoListView = this.FindControl("ManageFundsListView") as ListView; TextBox FindFundNoTextBox = ManageFundNoListView.FindControl("FindFundNoTextBox") as TextBox; if (IsPostBack) { DataPager pgr = ManageFundNoListView.FindControl("DataPager1") as DataPager; if (pgr != null && ManageFundNoListView.Items.Count != pgr.TotalRowCount) { pgr.SetPageProperties(0, pgr.MaximumRows, false); BindFundNoTable(); } else { DataPager pager = (DataPager)((ListView)sender).FindControl("DataPager1"); pager.SetPageProperties(e.StartRowIndex, e.MaximumRows, false); BindFundNoTable(); } } }Catherine Sh...
All-Star
23382 Points
2490 Posts
Microsoft
Re: Asp.net paging and search function not working
Oct 16, 2012 02:07 AM|LINK
Hi,
In order to resolve your issue, please try to simply your project and upload it to skydrive. Then provide the link. I want to test locally and try to resolve it.
Best wishes,
Feedback to us
Develop and promote your apps in Windows Store
caolong
Member
5 Points
31 Posts
Re: Asp.net paging and search function not working
Oct 16, 2012 06:32 PM|LINK
Hi,
I have included my Web Project and the AdventureWorks DB that I modified. Hopefully I simplified this enough.
My goal is to:
Note: No need to page back when I have found the item. I will have a refresh button that will refresh the entire list view. Also the webconfig needs to be modified with your own credentials.
Thanks for your time.
Database:
https://skydrive.live.com/redir?resid=9C0F92162F21D959!106&authkey=!AEyFlaB7dgbINys
WebProject
https://skydrive.live.com/redir?resid=9C0F92162F21D959!107&authkey=!AI659HEoHJ-DrBM
caolong
Member
5 Points
31 Posts
Re: Asp.net paging and search function not working
Oct 29, 2012 03:06 PM|LINK
Hi,
I am still lost here. Does anyone have any ideas what my problem is?
Thanks
caolong
Member
5 Points
31 Posts
Re: Asp.net paging and search function not working
Nov 01, 2012 05:19 PM|LINK
Hi
I posted a more simplified version here. Hopefully someone can help me. The AdventureWorks DB that I used in my project is included.
https://skydrive.live.com/redir?resid=681E062B4AC7A71F!112&authkey=!AF8u3TI0rSD2UAI
Thanks
srinivasupem...
Member
361 Points
64 Posts
Re: Asp.net paging and search function not working
Nov 29, 2012 04:46 AM|LINK
Hi,
You can check pagination explained well here
http://www.srinetinfo.com/2012/10/pagination-part-iv.html
Srinivasu Pemma
http://www.srinetinfo.com