Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gridview disable edit on 1 column asp.net

I am using a gridview Edit to edit the values i have in my gridview, when i press edit, all columns can be edited, i would like that one of the columns is not allowed to be edited.

Is there any way i can do this?

Thiss is my aspx code:

<asp:GridView 

ID="GridView1" 
runat="server" 
AllowSorting="True" 
OnRowCommand="GridView1_SelectedIndexChanged1" 
AutoGenerateEditButton="True" 
OnRowCancelingEdit="GridView1_RowCancelingEdit" 
CellSpacing="10"
OnRowUpdating="GridView1_RowUpdating" ShowFooter="True" 
onselectedindexchanged="GridView1_SelectedIndexChanged"
OnRowEditing="GridView1_RowEditing">



</asp:GridView>

Thanks

like image 293
Karl Avatar asked Aug 24 '11 06:08

Karl


1 Answers

If you are using asp:BoundField, try

<asp:BoundField DataField="CustomerID"
        ReadOnly="true"      
        HeaderText="Customer ID"/>

Or else if you are using asp:TemplateField, you can either

  1. Render it in either an asp:Label inside EditItemTemplate
  2. Omit the EditItemTemplate for that column altogether
like image 155
naveen Avatar answered Oct 05 '22 08:10

naveen