C#。行和.Cells不起作用

法比奥有

我正在使用ASP.NET GridView,现在我想自动定义colspan。我有VB代码,并将其转换为C#。我的代码当前看起来像这样,但是.Cells和.Rows无法正常工作。有谁知道这是怎么回事。我不可以使用这些吗?+我找到了正确的命名空间:System.Windows.Forms,但随后我还需要使用System.Windows.Forms.DataGridViewCellCollection; 但是我放在哪里呢?

 protected void grdvCamp_DataBound1(object sender, EventArgs e)
{
    for (int rowIndex = grdvCamp.Rows.Count - 2; rowIndex >= 0; rowIndex += -1)
    {
        GridViewRow gvRow = grdvCamp.Rows(rowIndex);
        GridViewRow gvPreviousRow = grdvCamp.Rows(rowIndex + 1);
        for (int cellCount = 0; cellCount <= gvRow.Cells.Count - 9; 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;
            }
        }
    }
}
索纳·古努尔(Soner Gonul)

我认为正确的语法应该是

.Rows[rowIndex]
.Cells[cellCount]

代替

.Rows(rowIndex)
.Cells(cellCount)

因为两个都返回一个集合。据我所知,()语法在vb.net中[]使用,在C#中使用。使用grdvCamp.Rows(rowIndex)C#编写时,它看起来Rows是的方法grdvCamp,而不是集合。

了解更多信息;

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章