0

将 gridview 中的特定列设置为只读非常简单。但我只需要将第一行或选定的行设为只读。是否可以在不影响其他可编辑行的情况下实现这一点。

这是我当前的代码。(样本)

   <Columns>                
        <asp:CommandField ShowEditButton="True" HeaderText="Edit" />
        <asp:BoundField DataField="Col1" ReadOnly="true" />
        <asp:BoundField DataField="Col2" ReadOnly="false" />
        <asp:BoundField DataField="Col3" ReadOnly="false" />

在行透视图中。第一列始终是只读的,其他两行是可编辑的。我不希望编辑按钮出现在第一行。我希望第一行完全只读。如何做到这一点?

编辑:

如果上面很难实现,那么我很想知道如何将数据表中的第一行添加到 gridview 的页脚行(假设 commandField 不会向页脚添加编辑按钮......)

4

1 回答 1

0

To make the first row non editable, you can use RowDataBound event of the GridView and hide the Edit button

First convert your CommandField to a TemplateField and Hide the Edit Button in RowDataBound event,

Try something like

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{

    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        if (e.Row.RowIndex == 0)
        {
            e.Row.FindControl("EditLinkButtonName").Visible = false;
        }
    }
}
于 2014-07-10T03:43:21.077 回答