我正在开发一个 .Net 项目,但 GridView 存在一些问题。
我的页面中有几个按钮。当我单击绑定我的 GridView 的按钮时,一切正常,但之后,当我单击其他按钮时,在 Rows 的末尾又出现了一个空单元格,其中包含文本“Monday”。
有人可以告诉我问题是什么吗?
谢谢
这是我的代码。
protected void GridView1_RowDataBound1(object sender, GridViewRowEventArgs e)
{
if (e.Row.Cells[0].Text.Contains("Monday"))
{
e.Row.BackColor = Color.Gray;
e.Row.ForeColor = Color.White;
e.Row.Cells[0].ColumnSpan = 2;
e.Row.Cells.Remove(e.Row.Cells[1]);
e.Row.Cells[1].HorizontalAlign = HorizontalAlign.Center;
e.Row.Cells[2].HorizontalAlign = HorizontalAlign.Center;
e.Row.Cells[3].HorizontalAlign = HorizontalAlign.Center;
e.Row.Cells[4].HorizontalAlign = HorizontalAlign.Center;
}
else
{
e.Row.Cells[0].Width = 45;
e.Row.Cells[1].Width = 400;
e.Row.Cells[2].Width = 40;
e.Row.Cells[3].Width = 40;
e.Row.Cells[4].Width = 40;
e.Row.Cells[5].Width = 40;
e.Row.Cells[0].HorizontalAlign = HorizontalAlign.Center;
e.Row.Cells[2].HorizontalAlign = HorizontalAlign.Center;
e.Row.Cells[3].HorizontalAlign = HorizontalAlign.Center;
e.Row.Cells[4].HorizontalAlign = HorizontalAlign.Center;
e.Row.Cells[5].HorizontalAlign = HorizontalAlign.Center;
}
}