【问题标题】:Asp.net gridview rowupdated event e.Tow.RowType type?Asp.net gridview rowupdated 事件 e.Tow.RowType 类型?
【发布时间】:2026-02-09 06:25:01
【问题描述】:

我在 GridView1_RowDataBound 事件中有一些代码用于表格的 html 设计:

if (e.Row.RowType == DataControlRowType.Header)
        {
            e.Row.TableSection = TableRowSection.TableHeader;

        }
        else if (e.Row.RowType == DataControlRowType.DataRow)
        {
            TableCellCollection cell = e.Row.Cells;
            cell[0].Attributes.Add("data-title", "");
            cell[1].Attributes.Add("data-title", "Product"  

        }

行更新后,我需要再次执行此操作,但我不能。因为 RowUpdated EventArgs 没有 Row 属性。我该如何解决这个问题?

【问题讨论】:

    标签: c# asp.net gridview objectdatasource


    【解决方案1】:

    您也可以在 RowDataBound 事件之外循环 GridView 行。

    foreach (GridViewRow row in GridView1.Rows)
    {
        TableCellCollection cell = row.Cells;
        cell[0].Attributes.Add("data-title", "");
        cell[1].Attributes.Add("data-title", "Product");
    }
    

    您可以使用此访问标题行

    GridView1.HeaderRow.Cells[0].Attributes.Add("data-title", "");
    

    【讨论】:

    • 是的。谢谢,但它不适用于标题类型。 if (e.Row.RowType == DataControlRowType.Header) { e.Row.TableSection = TableRowSection.TableHeader; }
    • 更新了我的答案。您也可以访问标题行。
    • 我稍微改变了你的答案。我删除了 if 语句“ if (e.Row.RowType == DataControlRowType.Header)”,只使用了: GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;你的回答当然是对的。谢谢