如何在asp.net的单独页面中显示gridview的每一行? [英] how to display the each row of gridview in a separate page in asp.net?

查看:105
本文介绍了如何在asp.net的单独页面中显示gridview的每一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi开发人员,

如何在单独的页面上显示Gridview的每一行?

示例:假设Gridview由10行组成.
现在我想在单独的页面中显示每一行,就像网格视图的第一行显示为输出一样.当第二行进入网格视图时,应该擦除第一行,并且该页面上应该只有第二行.就像明智.....
这是我的代码:

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:

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();
   }                
}


但没有得到我想要的结果.
谢谢你

问候,
Thiru


but not getting the result which i want.
Thank u

Regards,
Thiru

推荐答案

您可以将查询字符串与要显示的项目的ID发送到下一页,并且可以使用此ID轻松添加数据

享受
ashok kumar saini
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


执行页面大小属性pagesize = 1,那么它将逐行更改页面更改
do page size properties pagesize=1 then it will change row by row page change


如果我们要更改数据网格,我们必须使用行数据绑定事件.

受保护的void GridView1_RowDataBound(对象发送者,GridViewRowEventArgs e)
{

如果(e.Row.RowType == DataControlRowType.DataRow)
{
//我们只对包含数据的行感兴趣
//获取对用于对行进行数据绑定的数据的引用
DataRowView drv =(DataRowView)e.Row.DataItem;
int breakAfterRecords = 1;
如果(e.Row.RowIndex%breakAfterRecords == 0)
e.Row.Cells [0] .Text =<已移除的类=" \"pagebreak \""=" =">;



}

}
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\""="">";



}

}


这篇关于如何在asp.net的单独页面中显示gridview的每一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆