Aspdotnet-Suresh

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

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

Jun 8, 2015
Introduction

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

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

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" />
<Columns>
<asp:BoundField DataField="productid" HeaderText="Product Id" ReadOnly="true" />
<asp:BoundField DataField="productname" HeaderText="Product Name" ReadOnly="true" />
<asp:TemplateField HeaderText = "Price">
<ItemTemplate>
<asp:Label ID="lblPrice" runat="server" Text='<%# Eval("price")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:HiddenField ID="hdnprice" runat="server" Value='<%#Eval("price") %>' />
<asp:DropDownList ID = "ddlprice" runat = "server">
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
</Columns>
</asp:GridView>
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 Asp.net, C#.net, 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

0 comments :

Give your Valuable Comments

Other Related Posts

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