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.
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
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. |
|||
|
|||
0 comments :
Note: Only a member of this blog may post a comment.