Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何测试数据绑定中的交替行_C#_Asp.net_Gridview - Fatal编程技术网

C# 如何测试数据绑定中的交替行

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

这段代码在我选择编辑的第一行下插入一行,但当我编辑第二行时,现在会出现一个新行,有人能告诉我或告诉我如何更正吗。我试过做e.Row.RowInex+1,但没有行。但是如果我做e.Row.RowInex+2,我会得到第一行的一个新行,而不是第二行

    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
        }
    }
}