Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PagedDataSource problem

Status
Not open for further replies.

barrykellett

Programmer
Mar 4, 2003
29
GB
I have a Major headache with this so help please... Say I have a search page which has two panels (only one ever visible at a time).
I have a search panel, which has a few inputs an creates a sql query and dataset.when submitted, search panel is hidden, and results panel is shown.
I tie a PagedDataSource to the dataset, and it displays the appropriate number of rows etc... however the paging is broke. When I click to go to page 2 or whatever, the postback basically resets the whole thing... and I
dont get the second page of results, I get dropped back at search panel.
How do you guys manage whats oging to be shown and what data is going where, when working with many diff server controls on one asp.net page?

 
Not sure this will help you .. but I had a very similar issue and this is what I did...

'save dataview in cache
Cache("dvItems" & Session.SessionID) = dvItems

'In the PageIndexChanged event of the grid
SetPage(e.NewPageIndex)
gItems.DataBind()
'set the grid pages count to Global var pages


SetPage(page as int)
dvItems.RowFilter = ""
pages = dvItems.Count /gItems (grid) page size I set mine to 10 for easy math


'Index is a column in the dataview
Dim s As String = &quot;Index >= &quot; & (page - 1) * 10 + 1 & &quot; and Index <= &quot; & (page - 1) * 10 + 10

dvItems.RowFilter = s


'in the databinding event of the grid
gItems.DataSource = Cache(&quot;dvItems&quot; & Session.SessionID)


 
You can just use a datagrid with paring enabled. And handle the post back in the Page_Load event:
Code:
html:
<asp:datagrid id=&quot;dgResult&quot; runat=&quot;server&quot; AllowPaging=&quot;True&quot; PageSize=&quot;10&quot;>
<PagerStyle Position=&quot;Bottom&quot; Mode=&quot;NumericPages&quot; />
....
....
</asp:datagrid>
<asp:button id=&quot;btnSearch&quot; runat=server Text=&quot;Search&quot; />

code behind:
private void Page_Load(object sender, System.EventArgs e)
{
  if(!Page.IsPostBack)
  {
    //first run: display search panel, hide result panel
  }
}

private void btnSearch_Click(object sender, System.EventArgs e)
{
 // re-bind the grid based on search criteria
 bindGrid();
}

private void bindGrid()
{
 //code to bind the grid based on search criteria
 dgResult.DataSource = myDataSet;
 dgResult.DataBind();
}

private void dgResult_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs changeArgs)
{
 rebind the grid;
 bindGrid();
}

private void InitializeComponent()
{
 this.dgResult.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.dgResult_PageIndexChanged);
 this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
 this.Load += new System.EventHandler(this.Page_Load);
}
 
Thanks for the replies, need2progm - did you do this for a datalist or datagrid? I cant use a datagrid as its a catalogue application and i have to be able to repeat the html code from left to right and not in a single column.
 
yes, that example was in a grid

but, I also use the Cache(&quot;dvItems&quot; & Session.SessionID)
to pull out objects by &quot;ID&quot; field and pull a property on them like LastName and bind it to other controls. Labels and a Dropdown List.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top