当前位置 : 主页 > 编程语言 > java >

asp.net GridView、DataGrid行单元格自动合并

来源:互联网 收集:自由互联 发布时间:2022-07-20
GridView原理和DataGrid一样 pre name = "code" class = "csharp" this.dg_list.DataSource = run.GetDataSet(strSQL.ToString());this.dg_list.DataBind();if (this.dg_list.Items.Count 0){ this.GroupRows(this.dg_list, 0);} /// summary /// 合同号


GridView原理和DataGrid一样

<pre name="code" class="csharp">

this.dg_list.DataSource = run.GetDataSet(strSQL.ToString());this.dg_list.DataBind();if (this.dg_list.Items.Count > 0){ this.GroupRows(this.dg_list, 0);}



/// <summary>
/// 合同号单元格自动合并
/// </summary>
/// <param name="gv"></param>
/// <param name="cellNum"></param>
protected void GroupRows(DataGrid dg, int cellNum)
{
int i = 0, rowSpanNum = 1;
while (i < dg.Items.Count - 1)
{
DataGridItem dgi = dg.Items[i];
for (++i; i < dg.Items.Count; i++)
{
DataGridItem dgiNext = dg.Items[i];


string TypeName = dgi.Cells[cellNum].Text;
string Next = dgiNext.Cells[cellNum].Text;


if (TypeName == Next)
{
dgiNext.Cells[cellNum].Visible = false;
rowSpanNum++;
}
else
{
dgi.Cells[cellNum].RowSpan = rowSpanNum;
rowSpanNum = 1;
break;
}
if (i == gv.Rows.Count - 1)
{
dgi.Cells[cellNum].RowSpan = rowSpanNum;
}
}
}
}



上一篇:不知不觉,我已经在C站创作四周年了
下一篇:没有了
网友评论