【问题标题】:Gridview adding row dynamically on RowDataBound with the same RowState (Alternate or Normal)Gridview 在 RowDataBound 上动态添加行,具有相同的 RowState(Alternate 或 Normal)
【发布时间】:2012-01-17 16:39:12
【问题描述】:

我根据 RowDataBound 事件当前绑定的 Row 在后面的代码上动态添加行。我希望添加的行与当前有界行的状态相同(备用或正常)这可能吗?

我正在做这样的事情,但它不符合我想要的。我希望动态添加的行与当前行相同。但事实并非如此。

protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if(e.Row.RowType == DataControlRowType.DataRow)
    {
        GVData data = e.Row.DataItem as GVData;  // not original object just for brevity
        if(data.AddHiddenRow)
        {
            // the row state here should be the same as the current
            GridViewRow tr = new GridViewRow(e.Row.RowIndex +1, e.Row.RowIndex + 1, DataControlRowType.DataRow, e.Row.RowState);
            TableCell newTableCell = new TableCell();
            newTableCell.Style.Add("display", "none");
            tr.Cells.Add(newTableCell);

            ((Table)e.Row.Parent).Rows.Add(tr);
        }
    }
}

【问题讨论】:

  • 那么有什么不同呢?是不是在错误的地方?出现了吗?
  • 不,它在正确的位置,但是您可以看到添加的行是隐藏行,当网格应用交替行时,它也会应用于隐藏行。我不想要对添加的行应用交替行。

标签: asp.net gridview rowstate


【解决方案1】:

好的,问题是 GridView 不识别 display:none 表示该行将被隐藏,因此将其视为其交替样式的一部分。在这种情况下,您需要自己明确地实现样式并将其从 gridview 定义中删除。

我很快就会添加一个半示例。

【讨论】:

    猜你喜欢
    • 2021-11-20
    • 1970-01-01
    • 2011-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-05
    • 2017-05-14
    • 2010-10-11
    相关资源
    最近更新 更多