Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear All,

I am having a asp.net page which is having a grid and it is having 4 pages. each page shows 10 items. When i click on the 2 or 3 or 4 the grid disappears.

i have handled the GridView1_PageIndexChanging but of no use.

Pleas help me
Posted
Comments
bjdestiny 16-Oct-13 2:20am    
can you specify the code???
Thanks7872 16-Oct-13 2:22am    
Use Improve question and post code for GridView1_PageIndexChanging event.
mvengaqua 16-Oct-13 2:31am    
GridView1.PageIndex = e.NewPageIndex
GridView1.DataBind()
Thanks7872 16-Oct-13 2:33am    
You have to fill your GridView again after paging. Binding GridView is not enough.
mvengaqua 16-Oct-13 2:37am    
If i ll fill the grid again will it not be showing all the items

1 solution

First of all,create one function that fills your GridView
protected void fillgrid()
{
   //create and open db connection
   SqlCommand cmd = new SqlCommand("select * from table", connection);
   DataSet ds = new DataSet();
   SqlDataAdapter da = new SqlDataAdapter(cmd);
   da.Fill(ds);
   GridView1.DataSource = ds;
   GridView1.DataBind();
   connection.Close();
}
Call this function as follows:
C#
protected void Page_Load(object sender, EventArgs e)
{
   if (!IsPostBack)
   {
       fillgrid();              
   }
}

And implement code as follows:
C#
protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
  GridView1.PageIndex = e.NewPageIndex;
  fillgrid();
}
Regards..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900