ASP.NET Gridview: Making a GridColumn noneditable in Edit mode



I came across a very common requirement in my project and thought that will have to find share with all.

article explains how to make a column, say Primary Key, in a gridview noneditable.

Create a Website

Create a new website File > New > Website


Design (.aspx)

Select gridview from the toolbox

Enable edit and add the required bound and template field according to the requirement











Include three events for the gridview:




Code Behind (.cs)

Do the databinding from code behind


Being a sample here I have bonded a list of objects to the GridView (Can be done according to the requirement).

void DataBindGrid()


List<Class1> lst = new

for (int i = 0; i < 10; i++)




MyProperty = i,

MyProperty1 = “String” + i



GridView2.DataSource = lst;








//Add the class objects to the list with two properties





//Binding to gridview


RowBound Event


To make the column 1 readonly on editing add this

Code Behind

void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)


BoundField bound = GridView2.Columns[1] as

      bound.InsertVisible = false;

      bound.ReadOnly = true;










Editing Event in codebehind

Along with editing we’ll have to handle


as well.

But here we’ll see about the editing event



void GridView2_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)


GridView2.EditIndex = -1;







Here we have seen how to make a column noneditab;e in edit mode of a Gridview.

Happy Coding J







Some silverlight tutorials

1. First Look at Silverlight 2 (

In this article, you will have a first look at Silverlight that focuses on enabling Rich Internet Application (RIA) development.

2. The Importance of an Impressive User Interface (

In this lesson of the Silverlight tutorial, you will learn about the elements used for drawing graphics and to animate graphics by using Expression Blend.

3.How to Start with Silverlight (

4.Creating a XAML project for the Web (

They are beginning this tutorial by the creation of a project for a Web application, running in a navigator, and who requires the Silverlight plug-in, plus the SDK for programmers.

5.      Silverlight Tutorials Collection (

A good and useful collection of Silverlight tutorials if you want to learn how to get start with it?

6.How To Create An Animated Navigation Bar (

This article is a tutorial on how to use Silverlight 2.0 to make a nifty animated navigation bar much like the one at the top of the website.

7.Virtual Earth Silverlight Minimap Tutorial (

In this tutorial author is going to show you how to create a simple styled minimap to use in your Virtual Earth Silverlight projects that looks exactly like the one we used in our Twittermap demo.

8.Silverlight 3 Photo Gallery Wall Application (

A downloadable source code of Silverlight 3 Photo Gallery Wall Application with useful information to understand how it was done.

9.Silverlight With Java Script Tutorial (

This tutorial will introduce interactive animation. With Interactive Animation, we have the ability to start and stop our animations when we want without having to resort to subterfuge.

10.  Creating Rich Data Forms in Silverlight 3 – Introduction (

In this article author will show you the basics of the DataForm control – what you can do with it and why you should use it. He will show you how you can bind an item or a collection of items to a data form. Microsoft guys have done a great job with this control, so there are many features that you can use directly without much pain.

11.  Securing Silverlight Application and WCF Service using ASP.Net Authentication Techniques (

In this article you can learn the securing Silverlight Application and WCF Service using ASP.Net Authentication Techniques.

12.  Animation Easings in Silverlight 3 (

In this author will describe in details how you can use the BackEase animation.

13.  The Silverlight BlockText Control (

The main idea is to let Silverlight’s Grid do the work. So at the beginning Author split the given string into words and draw them hidden into temporary grid, so he get the ActualWidth of each word.

14.  Introduction to XAML Browser Applications (

This article gives an introduction to XBAPs and provides information about the differences between WPF Standalone applications, Silverlight, and XBAPs. Nihar explains the steps used to create a sample XBAP application and how to deploy and run it.

15.  50 Silverlight Applications (

This is the collection of 50 sample applications developed in Silverlight.

Hello world!

Welcome to This is your first post. Edit or delete it and start blogging!