colspan gridview 行 [英] colspan gridview rows
问题描述
我已将行添加到 gridview.gridview 中有 20 列.我如何在 gridview 中执行类似 colspan 的功能,它可以在 2-3 列下显示 2-3 行并保留为 colspan.
I have added rows into gridview. There are 20 columns in gridview. How can i do a colspan-like feature in gridview which could show me 2-3 rows under 2-3 columns and remaining as a colspan.
基本上我希望在 gridview 的行上的 gridview 中实现 colspan.
Basically i wish to implement colspan in gridview on the rows of the gridview.
因此我现在的 gv 就像 ;
hence my present gv is like ;
Col 1 Col 2 Col 3 Col 4 ...... Col 20
Col 1 Col 2 Col 3 Col 4 ...... Col 20
Cell1 Cell2 Cell3 Cell 4 ...... Cell 20(对于第 1 行)
Cell1 Cell2 Cell3 Cell 4 ...... Cell 20 (For Rows # 1)
我希望有类似的东西
Col 1 Col 2 Col 3 Col 4 ...... Col 20
Col 1 Col 2 Col 3 Col 4 ...... Col 20
Cell1 Cell2 ...... Cell 20 (For Rows # 1)
如有任何疑问,请告诉我.
Let me know for any query.
谢谢
推荐答案
需要对GridView的OnRowCreated事件进行如下处理:
You need to handle the OnRowCreated event of the GridView as follows:
protected void grid_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[2].ColumnSpan = 2;
//now make up for the colspan from cell2
e.Row.Cells.RemoveAt(4);
}
}
你的标记应该是这样的:
Your markup should be something like this:
<asp:GridView runat="server" ID="grid" OnRowCreated="grid_RowCreated" >
在上面的例子中,我用这个填充了网格:
On the above example, I populated the grid with this:
DataTable dt = new DataTable();
for (int i = 0; i < 5; i++)
{
dt.Columns.Add("Col " + i);
}
for (int i = 0; i < 10; i++)
{
DataRow r = dt.NewRow();
r.ItemArray=new object[]{"row "+i,"row "+i,"row "+i,"row "+i,"row "+i};
dt.Rows.Add(r);
}
grid.DataSource = dt;
grid.DataBind();
它产生了这个:
我刚刚意识到您想让 ROWS(不一定是标题)具有特定的 colspan,在这种情况下您可以这样做:
I just realized that you wanted to have the ROWS (not necessarily the header) to have certain colspan, in which case you can do:
protected void grid_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[2].ColumnSpan = 2;
//now make up for the colspan from cell2
e.Row.Cells.RemoveAt(4);
}
}
它会产生:
这篇关于colspan gridview 行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!