• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 937
  • Last Modified:

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

DataSet ds = this.getTable(this.DropDownList1.SelectedValue);
                  
this.DataGrid1.DataSource=ds.Tables[0];
this.DataGrid1.DataMember=ds.Tables[0].TableName;

this.DataGrid1.DataBind();

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
0
joshuadavidlee
Asked:
joshuadavidlee
  • 2
1 Solution
 
sachiekCommented:
You bound it to label colum. then it is going to be obviously readonly.

Generate datagrid dynamically at runtime.


Sachi
0
 
sachiekCommented:
You can take a look at this article to create datagrid dynamically.

http://www.codeproject.com/aspnet/ASPNET_DataGrid_creation.asp


Sachi
0
 
b1xml2Commented:
aspx code
========

also,
this.DataGrid1.DataSource = ds.Tables[0].DefaultView;
this.DataGrid1.DataBind();


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.
      //
      InitializeComponent();
      base.OnInit(e);
}

/// <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);

}
#endregion
0
 
joshuadavidleeAuthor Commented:
Hi

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.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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