DataGrid paging not working!

petem

Newcomer
Joined
Jul 7, 2004
Messages
2
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:
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
 
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}
 
Here's my Page_Load code:
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:
Code:
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();


Robby said:
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
 
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

Code:
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();
   }
 
Back
Top