gpt4 book ai didi

gridview - 如何在GridView中合并两个单元格

转载 作者:行者123 更新时间:2023-12-02 01:22:55 24 4
gpt4 key购买 nike

我在gridview中有一些数据,格式如下:

A     B
1
2 adeel
3
4 sml

现在,我想将该行与B列下的空白单元格合并。我该怎么做?

最佳答案

要合并同一列中的行,您可以使用如下代码:

public static void GroupRows(GridView GridView1, int cellNum)
{
int i = 0, rowSpanNum = 1;
while (i < GridView1.Rows.Count - 1)
{
GridViewRow gvr = GridView1.Rows[i];
for (++i; i < GridView1.Rows.Count; i++)
{
GridViewRow gvrNext = GridView1.Rows[i];
if (gvr.Cells[cellNum].Text != "" && gvrNext.Cells[cellNum].Text == "") ///here, chould change the term to suit other conditions, such like merging the same content of different rows in a same column.
{
gvrNext.Cells[cellNum].Visible = false;
rowSpanNum++;
}
else
{
gvr.Cells[cellNum].RowSpan = rowSpanNum;
rowSpanNum = 1;
break;
}
if (i == GridView1.Rows.Count - 1)
{
gvr.Cells[cellNum].RowSpan = rowSpanNum;
}
}
}
}

关于gridview - 如何在GridView中合并两个单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12512771/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com