两个自己写的合并GridView 行的方法
代码
public void MergeRow(GridView gv, int cellNum)
{
int i = 0;
int row = 0;
foreach (KeyValuePair<string, int> kp in this.HashECR)
{
GridViewRow gvr = gv.Rows[i];
gvr.Cells[cellNum].RowSpan = kp.Value;
row = row + kp.Value;
int next = i + 1;
for (int j = next; j < row; j++)
{
GridViewRow gvrNext = gv.Rows[j];
gvrNext.Cells[cellNum].Visible = false;
}
i = i + kp.Value;
}
}
{
int i = 0;
int row = 0;
foreach (KeyValuePair<string, int> kp in this.HashECR)
{
GridViewRow gvr = gv.Rows[i];
gvr.Cells[cellNum].RowSpan = kp.Value;
row = row + kp.Value;
int next = i + 1;
for (int j = next; j < row; j++)
{
GridViewRow gvrNext = gv.Rows[j];
gvrNext.Cells[cellNum].Visible = false;
}
i = i + kp.Value;
}
}
代码
public void MergeBomChangeRow(GridView gv, int cellNum)
{
int i = 0;
int allrow = 0;
while (i < gv.Rows.Count)
{
GridViewRow gvr = gv.Rows[i];
int row = int.Parse(((Label)gvr.FindControl("lblRows")).Text);
gvr.Cells[cellNum].RowSpan = row;
for (int j = 1; j < row; j++)
{
GridViewRow gvrNext = gv.Rows[j + i];
gvrNext.Cells[cellNum].Visible = false;
}
allrow = allrow + row;
i = allrow;
}
}
{
int i = 0;
int allrow = 0;
while (i < gv.Rows.Count)
{
GridViewRow gvr = gv.Rows[i];
int row = int.Parse(((Label)gvr.FindControl("lblRows")).Text);
gvr.Cells[cellNum].RowSpan = row;
for (int j = 1; j < row; j++)
{
GridViewRow gvrNext = gv.Rows[j + i];
gvrNext.Cells[cellNum].Visible = false;
}
allrow = allrow + row;
i = allrow;
}
}