且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

删除Gridview中的最后一个空行

更新时间:2023-10-12 13:26:52

for (int i = 1; i < dataGridView1.RowCount - 1; i++)
{
   Boolean isEmpty = true;
   for(int j=0;j<dataGridView1.Columns.Count; j++)
   {
     if (dataGridView1.Rows[i].Cells[j].Value.ToString() != "" )
      {
          isEmpty = false;
          break;
      }
    }
    if (isEmpty)
    {
       dataGridView1.Rows.RemoveAt(i);
       i--;
    }
 }


AllowUsersToAddRow 设为false。顺便说一下,你可能想要指定 DataGridView 而不是 GridView ,因为后者是web控件。
Set AllowUsersToAddRow as false. BTW, you might want to specify DataGridView instead of GridView since latter is web control.