Note that there are some explanatory texts on larger screens.

plurals
  1. POGridview won't rebind data after changing Gridview page
    primarykey
    data
    text
    <p>I am trying to populate my gridview with amazon search results. At the moment when the page loads, datasource is filled with data. What I am trying to do is show the data after pressing the Search button, but it displays "No Records Found". I have tried many different ways, the only way it worked, was without postback, but then the issue was that every time I changed the page on the gridview, GetProducts("Playstation") command was initiated over again. </p> <p>The solution I have been searcing for: Load the page -> click button -> fill the gridview with data -> When choosing new page in gridview, data is displayed but Getproducts("Playstation") is not initiated again. </p> <p>Is there a way to do this ? </p> <pre><code>protected void Page_Load(object sender, EventArgs e) { Button1.Click += new EventHandler(this.GreetingBtn_Click); if (!Page.IsPostBack) { AmazonSearch us = new Amazon.PAAPI.AmazonSearch(); GridView1.DataSource = us.GetProducts("Playstation"); } } void Search(Object sender, EventArgs e) { Button clickedButton = (Button) sender; GridView1.DataBind(); } protected void grid_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; GridView1.DataBind(); } </code></pre> <p><strong>EDIT</strong></p> <p>I figured it out thanks to FastGeeks anwser. I added variable ds to the code. and made the following changes:</p> <pre><code>DataSet ds = new DataSet(); protected void Page_Load(object sender, EventArgs e) { Button1.Click += new EventHandler(this.GreetingBtn_Click); } void Search(Object sender, EventArgs e) { Button clickedButton = (Button) sender; AmazonSearch us = new Amazon.PAAPI.AmazonSearch(); ds.Tables.Add(us.GetProducts("Playstation")); GridView1.DataSource = ds; Session["ds"] = ds; GridView1.DataBind(); } protected void grid_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; ds = (DataSet)Session["ds"]; GridView1.DataSource = ds; GridView1.DataBind();; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload