aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Gridview Make Column (Cell) Not Editable (Read Only) in using C#, VB.NET

Jun 8, 2015

Here I will explain how to make
gridview columns or cells read only or not editable in gridview edititemtemplate in using c#, with example. By using readonly property we can set gridview column as read only or not editable using c#, with example.

In previous articles I explained set dropdownlist selected value in gridview edititemtemplate in, populate gridview based on dropdownlist selected value in,
group columns in gridview, Edit gridview row details in modalpopup and many articles relating to gridview,, c#, and jQuery. Now I will explain how to set or make gridview columns read only or not editable in edititemtemplate in using c#,

To make column or cell readonly we need to write the code like as shown below

Code Snippet to Set ReadOnly Property in Gridview

<asp:GridView runat="server" ID="gvDetails" AllowPaging="true" PageSize="10" AutoGenerateColumns="false">
<HeaderStyle CssClass="headerstyle" />
<asp:BoundField DataField="productid" HeaderText="Product Id" ReadOnly="true" />
<asp:BoundField DataField="productname" HeaderText="Product Name" ReadOnly="true" />
<asp:TemplateField HeaderText = "Price">
<asp:Label ID="lblPrice" runat="server" Text='<%# Eval("price")%>'></asp:Label>
<asp:HiddenField ID="hdnprice" runat="server" Value='<%#Eval("price") %>' />
<asp:DropDownList ID = "ddlprice" runat = "server">
<asp:CommandField ShowEditButton="True" />
If you observe above code we set ReadOnly="true" property in both productid and productname columns these will be ready only whenever we try to edit gridview. If you want to complete example check following article

I hope it helps you…

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest,, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email


Give your Valuable Comments

Other Related Posts

© 2015 All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.