1

I'm stuck at the moment on how to show my Grid Data in another page.

Basically I have a GridView name "gdvRiders" with Paging Enabled. The problem is when I click on Page 2, I get a blank Page with no Data. Can someone help me? I'm starting to learn c#

Here is my code:

protected void Page_Load(object sender, EventArgs e) { DataBase db = new DataBase(true); string strSQL; DataTable dt; if (!IsPostBack) { strSQL = "SELECT r.surname, r.firstname, cn.country, r.age, f.flagurl " + "FROM (Riders r INNER JOIN par_CountryNation cn ON r.countryid = cn.countryid) INNER JOIN par_Flags f ON cn.flagid = f.flagid "; dt = db.getDataTableAc(strSQL, "list_Riders"); gdvRiders.DataSource = dt; gdvRiders.DataBind(); } } protected void gdvRiders_PageIndexChanging(object sender, GridViewPageEventArgs e) { gdvRiders.PageIndex = e.NewPageIndex; gdvRiders.DataBind(); } } 
1
  • You don't need to reset the index and re-bind. GridView paging does that automatically. Commented Nov 17, 2012 at 15:20

1 Answer 1

1

You need to assgin data to datasource of grid. You should put the code to bind the gridview in separate function and call it from page_load and PageIndexChanging.

protected void gdvRiders_PageIndexChanging(object sender, GridViewPageEventArgs e) { strSQL = "SELECT r.surname, r.firstname, cn.country, r.age, f.flagurl " + "FROM (Riders r INNER JOIN par_CountryNation cn ON r.countryid = cn.countryid) INNER JOIN par_Flags f ON cn.flagid = f.flagid "; dt = db.getDataTableAc(strSQL, "list_Riders"); gdvRiders.PageIndex = e.NewPageIndex; gdvRiders.DataSource = dt; gdvRiders.DataBind(); } 
Sign up to request clarification or add additional context in comments.

1 Comment

Got it...Many Thanks for the fast reply.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.