Learn how to a build a cloud-first strategyRegister Now

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

How to programatically set a GridView's column readonly?

How to programatically set a GridView's column readonly?
0
andreom
Asked:
andreom
  • 2
1 Solution
 
realjordannaCommented:
You could directly access the textbox or whatever control you have in that column and set its readonly attribute to false.  This requires you convert your gridview column to a template.  

So if I have a template with a textbox named TextBox1 in that column, in code I could then access it like this:

foreach (GridViewRow row in GridView1.Rows)
{
        // Selects the text from the TextBox which is inside the GridView control
        ((TextBox)row.FindControl("TextBox1")).ReadOnly = false;
}

Hope that helps!
0
 
andreomAuthor Commented:
In fact what I need is to set a column readonly, accessing programaticaly the property we can set interactively on the gridview dialog
0
 
realjordannaCommented:
So if it not a template, but a bounded field this should work:

            BoundField col = (BoundField)(gridView1.Columns[2]);
            col.ReadOnly = false;
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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