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>
/// <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;
}
}
}
}