[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1389
  • Last Modified:

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.
0
NaumLitvin
Asked:
NaumLitvin
  • 2
  • 2
2 Solutions
 
LCARSx32Commented:
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("ClientID","ClientID");
            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?

-Ray
0
 
informaniacCommented:
GridView1.Columns[ColumnIndex].ReadOnly = true;

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

GridView1.Columns["ColumnName"].ReadOnly = true;
0
 
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...
readonly2.jpg
0
 
NaumLitvinAuthor Commented:
thanks!
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now