Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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

Posted

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();
  }

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...