How to set ReadOnly for a GridView column in C#?

I need to change ReadOnly from false to true for one column in GridView depending on who the user is. In my particular case it is a BoundField (also I would like to know how to do it for a Template field as well) and DataField is "dteRequired". I would like to code something like that right in the Page_Load handler:

GridView1.Columns["dteRequired"].ReadOnly = true;

but I am getting compile errors...

Any idea?
Thank you.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Are you sure your columns have been created at the point where you are trying to set them as read only?

The following worked fine in C# 2005:

            dgWeight.Columns.Add("Name", "Name");
            dgWeight.Columns.Add("ID", "ID");

            dgWeight.Columns["ClientID"].ReadOnly = true;
            dgWeight.Columns["Name"].ReadOnly = true;
            dgWeight.Columns["ID"].ReadOnly = true;
What are the errors it gives you?


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Obadiah ChristopherCommented:
GridView1.Columns[ColumnIndex].ReadOnly = true;

FOr eg: GridView1.Columns[4].ReadOnly = true;
Yes, but it also allows the column name as input:

GridView1.Columns["ColumnName"].ReadOnly = true;
NaumLitvinAuthor Commented:
Thank you all, but none of that works. Attached picture shows that ReadOnly is not available for selection (it is in Page_Load handler). 3 lines above show the code that does work...
NaumLitvinAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.