petem Posted July 7, 2004 Posted July 7, 2004 Hi, I have a Datagrid that returns search results. It was working fine but now when you click on a paging link it returns ALL records rather than just those returned from the search. Example: click on search: - searchresults.aspx shows 5 records saying '1 to 5 of 23' click on a link to page 2 or page 3 etc and: - searchresults.aspx shows 5 records saying '6 to 10 of 102' The paging links are default DataGrid paging links. The DataGrid is cached as 'dv'+ Session.SessionID, Does anyone know what may be going wrong? here's my PageIndexChanged code: private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e) { DataGrid1.CurrentPageIndex = e.NewPageIndex; DataGrid1.DataSource = (DataView)Cache["dv" + Session.SessionID]; DataGrid1.DataBind(); SetPageStats(); } thanks in advance, Pete Quote
Moderators Robby Posted July 7, 2004 Moderators Posted July 7, 2004 Are you doing the same databind routine in the Page Load event? If so place the routine in an IF block... if (! ispostback()){ // databind here} Quote Visit...Bassic Software
petem Posted July 7, 2004 Author Posted July 7, 2004 Here's my Page_Load code: if (!Page.IsPostBack) GetResults(); GetResults() also has the bind code in it. is this what you mean? Within GetResults() - after the connection string & SProc call etc: DataView dv = new DataView(ds.Tables[0]); Cache["dv" + Session.SessionID] = dv; if(dv.Count == 0) { NoRecordsFoundLabel.Text = "No Jobs Found."; NoRecordsFoundLabel.Visible = true; DataGrid1.Visible = false; } DataGrid1.DataSource = dv; DataGrid1.DataBind(); Are you doing the same databind routine in the Page Load event? If so place the routine in an IF block... if (! ispostback()){ // databind here} I stuck a Breakpoint in the code on the Page_Load and tried clicking a paging link. Page.IsPostBack was True. Dunno if this helps, cheers, Pete Quote
shroomy Posted July 7, 2004 Posted July 7, 2004 first, just to be sure... you did set the pagesize of the datagrid to be something reasonable right??? second, I am mostly a VB guy but Im going to try ... :) try this ICollection DataSource() { //fill your table here..... DataView dv = new DataView(ds.Tables[0]); return (ICollection)New DataView(ds.Tables[0]); } void GetResults() { DataGrid1.DataSource = dv; DataGrid1.DataBind(); } private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e) { DataGrid1.CurrentPageIndex = e.NewPageIndex; GetResults(); } Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.