Read only column needed with dataset bound at runtime in web datagrid

Posted on 2005-04-20
Last Modified: 2012-05-05
DataSet ds = this.getTable(this.DropDownList1.SelectedValue);


I want to make column 2 readonly in a web datagrid
I do not know if this column is considered bound or not or what it is but i need it to be read only because its the primary key.
no i can not use the designer in anyway for this.
please help using c# code please
Question by:joshuadavidlee
    LVL 11

    Accepted Solution

    You bound it to label colum. then it is going to be obviously readonly.

    Generate datagrid dynamically at runtime.

    LVL 11

    Expert Comment

    You can take a look at this article to create datagrid dynamically.

    LVL 23

    Expert Comment

    aspx code

    this.DataGrid1.DataSource = ds.Tables[0].DefaultView;

    sample code

    private void Page_Init(object sender,EventArgs e)
          this.DataGrid1.ItemCreated += new EventHandler(this.DataGrid1_ItemCreated);

    private void DataGrid1_ItemCreated(object sender, DataGridItemEventArgs e)
          if (e.Item.ItemType != ListItemType.Pager)
                // set the second column to being inviisble
                e.Cells[1].Visible = false;

    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
          // CODEGEN: This call is required by the ASP.NET Web Form Designer.

    /// <summary>
    ///            Required method for Designer support - do not modify
    ///            the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
          this.Load += new System.EventHandler(this.Page_Load);
          this.Init += new System.EventHandler(this.Page_Init);


    Author Comment


    I figured this out on my own I think.  I just set the underlying datacolumn in the datatable to read only and then when databind() is called that column is readonly.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    This video discusses moving either the default database or any database to a new volume.

    779 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

    12 Experts available now in Live!

    Get 1:1 Help Now