How to programatically set a GridView's column readonly?

Posted on 2006-06-01
Last Modified: 2008-03-17
How to programatically set a GridView's column readonly?
Question by:andreom
    LVL 1

    Expert Comment

    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!

    Author Comment

    In fact what I need is to set a column readonly, accessing programaticaly the property we can set interactively on the gridview dialog
    LVL 1

    Accepted Solution

    So if it not a template, but a bounded field this should work:

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

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
    The viewer will learn how to count occurrences of each item in an array.
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    26 Experts available now in Live!

    Get 1:1 Help Now