Reputation: 14361
Making specific columns in gridview to be read-only is quite straight forward. But I just need to make first or a chosen row to be read-only. Is it possible to achieve this without affecting other editable rows.
Here's my current code. (sample)
<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" />
In the row perspective. First column is always read-only and other two rows are editable. I don't want an edit button to appear in the first row. I want the first row to be entirely read-only. How to achieve this?
EDIT:
If above is tough to achieve, then make then I am keen to know how first row in datatable can be added to footer row of gridview (assuming commandField will not add an edit button to footer...)
Upvotes: 0
Views: 2223
Reputation: 11464
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;
}
}
}
Upvotes: 0