Click here to Skip to main content
15,896,368 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi developers,

How do i display each row of Gridview on a separate page?

Example: suppose a Gridview consits of a 10 rows.
Now i want to show each row in seperate page like when ever 1st row of a grid view it shows as a out put.when ever 2nd row comes in to grid view 1st row should be erased and only second row should be on that page. like wise.....
here is my code:
C#
foreach (GridViewRow gr in GridView1.Rows)
{
   if (gr.RowType == DataControlRowType.DataRow)
   {
      string strQuery1 = "select id,studentname,gender" + " from student";
      DataTable dt = new DataTable();
      SqlConnection con = new SqlConnection
                (ConfigurationManager.AppSettings["connection"].ToString());
      SqlDataAdapter sda1 = new SqlDataAdapter();
      SqlCommand cmd1 = new SqlCommand(strQuery1);
      cmd1.CommandType = CommandType.Text;
      cmd1.Connection = con;
      try
      {
          con.Open();
          sda1.SelectCommand = cmd1;
          sda1.Fill(dt);                   
      }
      catch (Exception ex)
      {
          throw ex;
      }
      finally
      {
          con.Close();
          sda1.Dispose();
          con.Dispose();
      }
      GridView2.DataSource = dt;
      GridView2.DataBind();
   }                
}

but not getting the result which i want.
Thank u

Regards,
Thiru
Posted
Updated 28-Mar-10 22:09pm
v2

You can send a query string to next page with the id of the item that you want to show and with this id you can fatch data easily

Enjoy
ashok kumar saini
 
Share this answer
 
do page size properties pagesize=1 then it will change row by row page change
 
Share this answer
 
if we want change the perticular row in a data grid we have to use row data bound event.

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{

if (e.Row.RowType == DataControlRowType.DataRow)
{
//We're only interested in Rows that contain data
//get a reference to the data used to databound the row
DataRowView drv = (DataRowView)e.Row.DataItem;
int breakAfterRecords = 1;
if (e.Row.RowIndex % breakAfterRecords == 0)
e.Row.Cells[0].Text="<removed class="\" pagebreak\""="">";



}

}
 
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