本文介绍了如何使用ROWSPAN在GridView的为第一纵队只的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
需要帮助来解决的GridView布局相关的一个问题。我想使用C#.NET语言来实现与ItemTemplate中列custome的GridView,并想用ROWSPAN属性包括视图。
Need help to resolve a issue related with Gridview layout. I am trying to implement custome Gridview with Itemtemplate Columns using C#.Net language and want to include view using RowSpan property.
我试着用下面code,但对我的
I tried to use below code but didn't work for me Here
请检查code这是我使用的:
Please check the code which i used:
protected void GridView31_DataBound1(object sender, EventArgs e)
{
for (int rowIndex = grdView31.Rows.Count - 2; rowIndex >= 0; rowIndex--)
{
GridViewRow gvRow = grdView31.Rows[rowIndex];
GridViewRow gvPreviousRow = grdView31.Rows[rowIndex + 1];
for (int cellCount = 0; cellCount < gvRow.Cells.Count; cellCount++)
{
if (gvRow.Cells[cellCount].Text == gvPreviousRow.Cells[cellCount].Text)
{
if (gvPreviousRow.Cells[cellCount].RowSpan < 2)
{
gvRow.Cells[cellCount].RowSpan = 2;
}
else
{
gvRow.Cells[cellCount].RowSpan =
gvPreviousRow.Cells[cellCount].RowSpan + 1;
}
gvPreviousRow.Cells[cellCount].Visible = false;
}
}
}
}
可是每次 gvRow.Cells [cellCount]。文本== GV previousRow.Cells [cellCount]。文本
是空白的。
因此,网格正在怪异形状。不知道这里发生了什么。
Hence the grid is taking weird shapes. Don't know what is happening here.
谁能帮助?
推荐答案
使用RowDataBound事件来代替:
Use RowDataBound event instead:
void GridView31_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow )
{
if (e.Row.RowIndex % 4 == 0)
{
e.Row.Cells[0].Attributes.Add("rowspan", "4");
}
else
{
e.Row.Cells[0].Visible = false;
}
}
}
这篇关于如何使用ROWSPAN在GridView的为第一纵队只的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!