日期:2014-05-18  浏览次数:20547 次

.net如何能这样显示数据呢???
输出如下:据情况而定,不止2行,n行
------------------------
|             |               |                       |     0.68       |     1.58         |     1.0           |
|   1         |   aaa       |       time1       |---------|----------|----------|
|             |               |                       |     0.68       |     1.58         |     1.0           |
------------------------
|             |               |                       |     0.5         |     1.22         |     0.2           |
|   2         |   bbb       |       time2       |---------|----------|----------|
|             |               |                       |     0.6         |     1.78         |     2.5           |
------------------------
第一条sql语句只能查询出前两项的内容   例如   aaa   ,     time1  
后面的数值是第二条或是第三条查询得出的数据结果,
要怎么做??
各位   帮帮忙

------解决方案--------------------
有许许多多方法可以实现,但是没有最适合你的形式的“顶级”方法。所以还是一言难尽。

Table、Repeater、DataList,甚至GridView做为“顶级”控件再展开都可以。例如我在帖子

http://community.csdn.net/Expert/topic/5508/5508424.xml?temp=.9861261

中回答过一个合并单元格的问题。其实这里说的4种顶级控件大同小异,都是用 rowspan 属性来处理你的前三列。


不过我在csdn上一般只回答很容易回答的问题,你的问题需要比较多的东西计划在一起,比较费口舌,同时我也不确定你适合使用什么办法。
------解决方案--------------------
lz试一试下面的代码,页面上放一个GridView,id为GridView1,加上OnRowDataBound= "GridView1_RowDataBound "属性就可以。
能看懂照着做就可以。
protected void Page_Load(object sender, EventArgs e)
{
GridView1.DataSource = getDataTable();
GridView1.DataBind();
}

private DataTable getDataTable()
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn( "name ", typeof(string)));
dt.Columns.Add(new DataColumn( "password ", typeof(string)));
DataRow dr;
for (int i = 0; i <= 10; i++)
{
dr = dt.NewRow();
if (i < 5)
dr[0] = "a ";
else
dr[0] = "b ";
dr[1] = i.ToString();
dt.Rows.Add(dr);
}
return dt;
}

int row = 0;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
int rowindex = e.Row.RowIndex;
if (rowindex - 1 < 0) return;
if (e.Row.Cells[0].Text == GridView1.Rows[rowindex - 1].Cells[0].Text)
{