0

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...)

bonCodigo
  • 14,268
  • 1
  • 48
  • 91

1 Answers1

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;
        }
    }
}
Nalaka526
  • 11,278
  • 21
  • 82
  • 116
  • If you by anychance had seen one of my earlier posts (question) there's a conflict between RowDataBound and RowDataUpdating events... So I am unable to use what you are suggesting for now at least... – bonCodigo Jul 10 '14 at 03:44
  • [As of today's status... `FindControl` is just not finding any control in my aspx page... no textboxes, no dropdownlists etc... When I say *any control*, I am referring to those controls added via `templatefields`.](http://stackoverflow.com/q/24771214/1389394) – bonCodigo Jul 16 '14 at 06:24