title: Disable editing on specific rows in Gridview asp.net
body: <p>I have one Gridview that Shows my Customer table. In my gridview it's possible for the user to Insert new customers and also edit existing customers. </p>
  
  <p>Now to my question. I have two customers that shouldnt be able for the user to edit but i want them to be showed in the gridview. Can i somehow disable the edit button or something for this customers? For example by saying that where = custID IN (60,61) edit button disabled?</p>
  
  <p>Here is the whole code for my gridview</p>
  
  <pre><code>&lt;asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False" CellPadding="3" DataKeyNames="CustID" DataSourceID="Event" GridLines="Horizontal" ShowFooter="True" AllowPaging="True" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px"&gt;
      &lt;AlternatingRowStyle BackColor="#F7F7F7" HorizontalAlign="Center" /&gt;
      &lt;Columns&gt;
          &lt;asp:CommandField ShowEditButton="True" /&gt;
          &lt;asp:TemplateField HeaderText="ID" InsertVisible="False" SortExpression="CustID"&gt;
              &lt;EditItemTemplate&gt;
                  &lt;asp:Label ID="Label1" runat="server" Text='&lt;%# Eval("CustID") %&gt;'&gt;&lt;/asp:Label&gt;
              &lt;/EditItemTemplate&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:Label ID="Label1" runat="server" Text='&lt;%# Bind("CustID") %&gt;'&gt;&lt;/asp:Label&gt;
              &lt;/ItemTemplate&gt;
              &lt;FooterTemplate&gt;
                  &lt;asp:LinkButton ValidationGroup="INSERT" OnClick="lbInsert_Click"  ID="lbInsert" runat="server" &gt;Insert&lt;/asp:LinkButton&gt;
              &lt;/FooterTemplate&gt;
          &lt;/asp:TemplateField&gt;
          &lt;asp:TemplateField HeaderText="Anrede" SortExpression="Gender"&gt;
              &lt;EditItemTemplate&gt;
                  &lt;asp:DropDownList ID="DropDownList3" runat="server" DataSourceID="SqlDataSource1" DataTextField="Gender" DataValueField="Gender" SelectedValue='&lt;%# Bind("Gender") %&gt;'&gt;
                  &lt;/asp:DropDownList&gt;
                  &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="&lt;%$ ConnectionStrings:EventConnectionString %&gt;" SelectCommand="SELECT DISTINCT [Gender] FROM [Customer]"&gt;&lt;/asp:SqlDataSource&gt;
              &lt;/EditItemTemplate&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:Label ID="Label2" runat="server" Text='&lt;%# Bind("Gender") %&gt;'&gt;&lt;/asp:Label&gt;
              &lt;/ItemTemplate&gt;
              &lt;FooterTemplate&gt;
                  &lt;div style="text-align: center;"&gt;&lt;asp:Label ID="Label13" runat="server" Text="Anrede"&gt;&lt;/asp:Label&gt;
                  &lt;asp:DropDownList ID="ddlGender" runat="server"&gt;
                      &lt;asp:ListItem&gt;Anrede Auswählen&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;Herr&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;Frau&lt;/asp:ListItem&gt;
                  &lt;/asp:DropDownList&gt;
                  &lt;asp:RequiredFieldValidator ID="rfvInsGender" runat="server" ErrorMessage="Anrede ist ein Pflichtfeld"
                      ControlToValidate="ddlGender" ValidationGroup="INSERT" Text="*" ForeColor="Red" InitialValue="Anrede Auswählen"&gt;
                  &lt;/asp:RequiredFieldValidator&gt;
                  &lt;/div&gt;
              &lt;/FooterTemplate&gt;
          &lt;/asp:TemplateField&gt;
          &lt;asp:TemplateField HeaderText="Name" SortExpression="LastName"&gt;
              &lt;EditItemTemplate&gt;
                  &lt;asp:TextBox ID="TextBox2" runat="server" Text='&lt;%# Bind("LastName") %&gt;'&gt;&lt;/asp:TextBox&gt;
                  &lt;asp:RequiredFieldValidator ID="rfvEdLastName" runat="server" ErrorMessage="Name ist ein Pflichtfeld"
                      ControlToValidate="TextBox2" Text="*" ForeColor="Red"&gt;
                  &lt;/asp:RequiredFieldValidator&gt;
              &lt;/EditItemTemplate&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:Label ID="Label3" runat="server" Text='&lt;%# Bind("LastName") %&gt;'&gt;&lt;/asp:Label&gt;
              &lt;/ItemTemplate&gt;
              &lt;FooterTemplate&gt;
                  &lt;div style="text-align: center;"&gt;&lt;asp:Label ID="Label14" runat="server" Text="Name"&gt;&lt;/asp:Label&gt;&lt;/div&gt;
                  &lt;asp:TextBox ID="txtLastName" runat="server"&gt;&lt;/asp:TextBox&gt;
                  &lt;asp:RequiredFieldValidator ID="rfvInsLastName" runat="server" ErrorMessage="Name ist ein Pflichtfeld"
                      ControlToValidate="txtLastName" ValidationGroup="INSERT" Text="*" ForeColor="Red"&gt;
                  &lt;/asp:RequiredFieldValidator&gt;
              &lt;/FooterTemplate&gt;
          &lt;/asp:TemplateField&gt;
          &lt;asp:TemplateField HeaderText="Vorname" SortExpression="FirstName"&gt;
              &lt;EditItemTemplate&gt;
                  &lt;asp:TextBox ID="TextBox3" runat="server" Text='&lt;%# Bind("FirstName") %&gt;'&gt;&lt;/asp:TextBox&gt;
                  &lt;asp:RequiredFieldValidator ID="rfvEdFirstName" runat="server" ErrorMessage="VorName ist ein Pflichtfeld"
                      ControlToValidate="TextBox3" Text="*" ForeColor="Red"&gt;
                  &lt;/asp:RequiredFieldValidator&gt;
              &lt;/EditItemTemplate&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:Label ID="Label4" runat="server" Text='&lt;%# Bind("FirstName") %&gt;'&gt;&lt;/asp:Label&gt;
              &lt;/ItemTemplate&gt;
              &lt;FooterTemplate&gt;
                  &lt;div style="text-align: center;"&gt;&lt;asp:Label ID="Label15" runat="server" Text="Vorname"&gt;&lt;/asp:Label&gt;&lt;/div&gt;
                  &lt;asp:TextBox ID="txtFirstName" runat="server"&gt;&lt;/asp:TextBox&gt;
                  &lt;asp:RequiredFieldValidator ID="rfvInsFirstName" runat="server" ErrorMessage="VorName ist ein Pflichtfeld"
                      ControlToValidate="txtFirstName" ValidationGroup="INSERT" Text="*" ForeColor="Red"&gt;
                  &lt;/asp:RequiredFieldValidator&gt;
              &lt;/FooterTemplate&gt;
          &lt;/asp:TemplateField&gt;
          &lt;asp:TemplateField HeaderText="Strasse" SortExpression="Street"&gt;
              &lt;EditItemTemplate&gt;
                  &lt;asp:TextBox ID="TextBox4" runat="server" Text='&lt;%# Bind("Street") %&gt;'&gt;&lt;/asp:TextBox&gt;
                  &lt;asp:RequiredFieldValidator ID="rfvEdStreet" runat="server" ErrorMessage="Strasse ist ein Pflichtfeld"
                      ControlToValidate="TextBox4" Text="*" ForeColor="Red"&gt;
                  &lt;/asp:RequiredFieldValidator&gt;
              &lt;/EditItemTemplate&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:Label ID="Label5" runat="server" Text='&lt;%# Bind("Street") %&gt;'&gt;&lt;/asp:Label&gt;
              &lt;/ItemTemplate&gt;
              &lt;FooterTemplate&gt;
                  &lt;div style="text-align: center;"&gt;&lt;asp:Label ID="Label16" runat="server" Text="Strasse"&gt;&lt;/asp:Label&gt;&lt;/div&gt;
                  &lt;asp:TextBox ID="txtStreet" runat="server"&gt;&lt;/asp:TextBox&gt;
                  &lt;asp:RequiredFieldValidator ID="rfvInsStreet" runat="server" ErrorMessage="Strasse ist ein Pflichtfeld"
                      ControlToValidate="txtStreet" ValidationGroup="INSERT" Text="*" ForeColor="Red"&gt;
                  &lt;/asp:RequiredFieldValidator&gt;
              &lt;/FooterTemplate&gt;
          &lt;/asp:TemplateField&gt;
          &lt;asp:TemplateField HeaderText="House Nr" SortExpression="HouseNr"&gt;
              &lt;EditItemTemplate&gt;
                  &lt;asp:TextBox ID="TextBox5" runat="server" Text='&lt;%# Bind("HouseNr") %&gt;'&gt;&lt;/asp:TextBox&gt;
                  &lt;asp:RequiredFieldValidator ID="rfvEdHouseNr" runat="server" ErrorMessage="House Nr ist ein Pflichtfeld"
                      ControlToValidate="TextBox5" Text="*" ForeColor="Red"&gt;
                  &lt;/asp:RequiredFieldValidator&gt;
              &lt;/EditItemTemplate&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:Label ID="Label6" runat="server" Text='&lt;%# Bind("HouseNr") %&gt;'&gt;&lt;/asp:Label&gt;
              &lt;/ItemTemplate&gt;
              &lt;FooterTemplate&gt;
                  &lt;div style="text-align: center;"&gt;&lt;asp:Label ID="Label17" runat="server" Text="House Nr"&gt;&lt;/asp:Label&gt;&lt;/div&gt;
                  &lt;asp:TextBox ID="txtHouseNr" runat="server"&gt;&lt;/asp:TextBox&gt;
                  &lt;asp:RequiredFieldValidator ID="rfvInsHouseNr" runat="server" ErrorMessage="House Nr ist ein Pflichtfeld"
                      ControlToValidate="txtHouseNr" ValidationGroup="INSERT" Text="*" ForeColor="Red"&gt;
                  &lt;/asp:RequiredFieldValidator&gt;
              &lt;/FooterTemplate&gt;
          &lt;/asp:TemplateField&gt;
          &lt;asp:TemplateField HeaderText="PLZ" SortExpression="Zip"&gt;
              &lt;EditItemTemplate&gt;
                  &lt;asp:TextBox ID="TextBox6" runat="server" Text='&lt;%# Bind("Zip") %&gt;'&gt;&lt;/asp:TextBox&gt;
                  &lt;asp:RequiredFieldValidator ID="rfvEdZip" runat="server" ErrorMessage="PLZ ist ein Pflichtfeld"
                      ControlToValidate="TextBox6" Text="*" ForeColor="Red"&gt;
                  &lt;/asp:RequiredFieldValidator&gt;
              &lt;/EditItemTemplate&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:Label ID="Label7" runat="server" Text='&lt;%# Bind("Zip") %&gt;'&gt;&lt;/asp:Label&gt;
              &lt;/ItemTemplate&gt;
              &lt;FooterTemplate&gt;
                  &lt;div style="text-align: center;"&gt;&lt;asp:Label ID="Label18" runat="server" Text="PLZ"&gt;&lt;/asp:Label&gt;&lt;/div&gt;
                  &lt;asp:TextBox ID="txtZip" runat="server"&gt;&lt;/asp:TextBox&gt;
                  &lt;asp:RequiredFieldValidator ID="rfvInsZip" runat="server" ErrorMessage="PLZ ist ein Pflichtfeld"
                      ControlToValidate="txtZip" ValidationGroup="INSERT" Text="*" ForeColor="Red"&gt;
                  &lt;/asp:RequiredFieldValidator&gt;
              &lt;/FooterTemplate&gt;
          &lt;/asp:TemplateField&gt;
          &lt;asp:TemplateField HeaderText="Ort" SortExpression="City"&gt;
              &lt;EditItemTemplate&gt;
                  &lt;asp:TextBox ID="TextBox7" runat="server" Text='&lt;%# Bind("City") %&gt;'&gt;&lt;/asp:TextBox&gt;
                  &lt;asp:RequiredFieldValidator ID="rfvEdCity" runat="server" ErrorMessage="Ort ist ein Pflichtfeld"
                      ControlToValidate="TextBox7" Text="*" ForeColor="Red"&gt;
                  &lt;/asp:RequiredFieldValidator&gt;
              &lt;/EditItemTemplate&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:Label ID="Label8" runat="server" Text='&lt;%# Bind("City") %&gt;'&gt;&lt;/asp:Label&gt;
              &lt;/ItemTemplate&gt;
              &lt;FooterTemplate&gt;
                  &lt;div style="text-align: center;"&gt;&lt;asp:Label ID="Label19" runat="server" Text="Ort"&gt;&lt;/asp:Label&gt;&lt;/div&gt;
                  &lt;asp:TextBox ID="txtCity" runat="server"&gt;&lt;/asp:TextBox&gt;
                  &lt;asp:RequiredFieldValidator ID="rfvInsCity" runat="server" ErrorMessage="Ort ist ein Pflichtfeld"
                      ControlToValidate="txtCity" ValidationGroup="INSERT" Text="*" ForeColor="Red"&gt;
                  &lt;/asp:RequiredFieldValidator&gt;
              &lt;/FooterTemplate&gt;
          &lt;/asp:TemplateField&gt;
          &lt;asp:TemplateField HeaderText="Telefon" SortExpression="Phone"&gt;
              &lt;EditItemTemplate&gt;
                  &lt;asp:TextBox ID="TextBox8" runat="server" Text='&lt;%# Bind("Phone") %&gt;'&gt;&lt;/asp:TextBox&gt;
              &lt;/EditItemTemplate&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:Label ID="Label9" runat="server" Text='&lt;%# Bind("Phone") %&gt;'&gt;&lt;/asp:Label&gt;
              &lt;/ItemTemplate&gt;
              &lt;FooterTemplate&gt;
                  &lt;div style="text-align: center;"&gt;&lt;asp:Label ID="Label20" runat="server" Text="Telefon"&gt;&lt;/asp:Label&gt;&lt;/div&gt;
                  &lt;asp:TextBox ID="txtPhone" runat="server"&gt;&lt;/asp:TextBox&gt;
              &lt;/FooterTemplate&gt;
          &lt;/asp:TemplateField&gt;
          &lt;asp:TemplateField HeaderText="E-mail" SortExpression="Email"&gt;
              &lt;EditItemTemplate&gt;
                  &lt;asp:TextBox ID="TextBox9" runat="server" Text='&lt;%# Bind("Email") %&gt;'&gt;&lt;/asp:TextBox&gt;
              &lt;/EditItemTemplate&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:Label ID="Label10" runat="server" Text='&lt;%# Bind("Email") %&gt;'&gt;&lt;/asp:Label&gt;
              &lt;/ItemTemplate&gt;
              &lt;FooterTemplate&gt;
                  &lt;div style="text-align: center;"&gt;&lt;asp:Label ID="Label21" runat="server" Text="E-mail"&gt;&lt;/asp:Label&gt;&lt;/div&gt;
                  &lt;asp:TextBox ID="txtEmail" runat="server"&gt;&lt;/asp:TextBox&gt;
              &lt;/FooterTemplate&gt;
          &lt;/asp:TemplateField&gt;
          &lt;asp:TemplateField HeaderText="Firma" SortExpression="Company"&gt;
              &lt;EditItemTemplate&gt;
                  &lt;asp:TextBox ID="TextBox10" runat="server" Text='&lt;%# Bind("Company") %&gt;'&gt;&lt;/asp:TextBox&gt;
              &lt;/EditItemTemplate&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:Label ID="Label11" runat="server" Text='&lt;%# Bind("Company") %&gt;'&gt;&lt;/asp:Label&gt;
              &lt;/ItemTemplate&gt;
              &lt;FooterTemplate&gt;
                  &lt;div style="text-align: center;"&gt;&lt;asp:Label ID="Label22" runat="server" Text="Firma"&gt;&lt;/asp:Label&gt;&lt;/div&gt;
                  &lt;asp:TextBox ID="txtCompany" runat="server"&gt;&lt;/asp:TextBox&gt;
              &lt;/FooterTemplate&gt;
          &lt;/asp:TemplateField&gt;
          &lt;asp:TemplateField HeaderText="Status" SortExpression="Active"&gt;
              &lt;EditItemTemplate&gt;
                  &lt;asp:DropDownList ID="DropDownList4" runat="server" DataSourceID="SqlDataSource2" DataTextField="Active" DataValueField="Active" SelectedValue='&lt;%# Bind("Active") %&gt;'&gt;
                  &lt;/asp:DropDownList&gt;
                  &lt;asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="&lt;%$ ConnectionStrings:EventConnectionString %&gt;" SelectCommand="SELECT DISTINCT [Active] FROM [Customer]"&gt;&lt;/asp:SqlDataSource&gt;
              &lt;/EditItemTemplate&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:Label ID="Label12" runat="server" Text='&lt;%# Bind("Active") %&gt;'&gt;&lt;/asp:Label&gt;
              &lt;/ItemTemplate&gt;
              &lt;FooterTemplate&gt;
                  &lt;div style="text-align: center;"&gt;&lt;asp:Label ID="Label23" runat="server" Text="Status"&gt;&lt;/asp:Label&gt;&lt;/div&gt;
                  &lt;asp:DropDownList ID="ddlActive" runat="server"&gt;
                      &lt;asp:ListItem&gt;Status Auswählen&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;Aktiv&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;Passiv&lt;/asp:ListItem&gt;
                  &lt;/asp:DropDownList&gt;
                  &lt;asp:RequiredFieldValidator ID="rfvInsActive" runat="server" ErrorMessage="Status ist ein Pflichtfeld"
                      ControlToValidate="ddlActive" ValidationGroup="INSERT" Text="*" ForeColor="Red" InitialValue="Status Auswählen"&gt;
                  &lt;/asp:RequiredFieldValidator&gt;
              &lt;/FooterTemplate&gt;
          &lt;/asp:TemplateField&gt;
  
      &lt;/Columns&gt;
      &lt;FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" /&gt;
      &lt;HeaderStyle BackColor="#B5C7DE" Font-Bold="True" ForeColor="#4A3C8C" /&gt;
      &lt;PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" /&gt;
      &lt;RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Center" /&gt;
      &lt;SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" /&gt;
      &lt;SortedAscendingCellStyle BackColor="#F4F4FD" /&gt;
      &lt;SortedAscendingHeaderStyle BackColor="#5A4C9D" /&gt;
      &lt;SortedDescendingCellStyle BackColor="#D8D8F0" /&gt;
      &lt;SortedDescendingHeaderStyle BackColor="#3E3277" /&gt;
  &lt;/asp:GridView&gt;
  </code></pre>