Suppose i need to write a control that uses the DataGrid control. Then in
a typical senario i have:
protected DataGrid Grid;
.
.
.
protected override void CreateChildControls() {
Grid.ID = "MyGrid";
Grid.Width = gridWidth;
Grid.BackColor = Color.FromName("#ccccff");
Grid.BorderColor = Color.Black;
Grid.ShowFooter = false;
Grid.CellPadding = 3;
Grid.CellSpacing = 0;
Grid.Font.Name = "Verdana";
Grid.Font.Size = 8;
Grid.HeaderStyle.BackColor = Color.FromName("#aaaadd");
Grid.HeaderStyle.Font.Bold = true;
Grid.AutoGenerateColumns = false;
Grid.SelectedItemStyle.BackColor = Color.LightCyan;
Grid.SelectedItemStyle.Font.Bold = true;
Grid.AllowPaging = true; Grid.PageSize = gridPageSize;
Grid.PagerStyle.BackColor = Color.FromName("#aaaadd");
Grid.PagerStyle.HorizontalAlign = HorizontalAlign.Right;
.
.
.
Now, before databinding i want to specify some columns. Adding
BoundColumns seems easy. I specify a function:
public BoundColumn AddBoundColumn(String strHeaderText, String
strDataField, int iWidth, bool bReadOnly) {
BoundColumn bc = new BoundColumn();
bc.HeaderText = strHeaderText;
bc.DataField = strDataField;
bc.HeaderStyle.Width = iWidth;
bc.ReadOnly = bReadOnly;
return bc;
}
and i call it somehow like:
Grid.Columns.Add(AddBoundColumn(string1"].ToString(), string2.ToString(),
100, true));
The problem is that there doesn 't seem to be a way to create a similar
function to add a TemplateColumn in c# code so i can have programmatic
access to ItemTemplate and EditItemTemplate.
can anyone help me?