C# 如何测试数据绑定中的交替行
这段代码在我选择编辑的第一行下插入一行,但当我编辑第二行时,现在会出现一个新行,有人能告诉我或告诉我如何更正吗。我试过做e.Row.RowInex+1,但没有行。但是如果我做e.Row.RowInex+2,我会得到第一行的一个新行,而不是第二行C# 如何测试数据绑定中的交替行,c#,asp.net,gridview,C#,Asp.net,Gridview,这段代码在我选择编辑的第一行下插入一行,但当我编辑第二行时,现在会出现一个新行,有人能告诉我或告诉我如何更正吗。我试过做e.Row.RowInex+1,但没有行。但是如果我做e.Row.RowInex+2,我会得到第一行的一个新行,而不是第二行 protected void PageSettings_DataBound(object sender, GridViewRowEventArgs e) { if ((e.Row.RowState & DataContro
protected void PageSettings_DataBound(object sender, GridViewRowEventArgs e)
{
if ((e.Row.RowState & DataControlRowState.Edit) > 0))
{
GridViewRow row = new GridViewRow(e.Row.RowIndex + 2, -1, DataControlRowType.DataRow, DataControlRowState.Normal);
row.Cells.AddRange(CreateCells());
Table table = e.Row.Parent as Table;
table.Rows.AddAt(e.Row.RowIndex + 2, row);
}
}
private TableCell[] CreateCells()
{
TableCell[] cells = new TableCell[2];
TableCell cell;
cell = new TableCell();
cell.ColumnSpan = 2;
cells[0] = cell;
cell = new TableCell();
cell.ColumnSpan = 4;
cells[1] = cell;
return cells;
}
解决了任何一个有这个问题的人
((e.Row.RowState & DataControlRowState.Edit) > 0)
对于标题问题“如何在数据绑定中测试交替行”的回答:
protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Alternate)
{
// alternate rows
}
}
}