asp.net column gridview widths


public class ColumnHeaderTemplate : ITemplate
{
    private string columnname;
    private string displayname;
    public ColumnHeaderTemplate(string inColumnname, string inDisplayName)
    {
        displayname = inDisplayName;
        columnname = inColumnname;
    }
    public void InstantiateIn(Control container)
    {
        Label test = new Label();
        test.Text = this.displayname;

        LiteralControl lc = new LiteralControl("<p/>");
        TextBox tb = new TextBox();
        tb.Style.Value = "display:block;";
        tb.ID = this.columnname;
        tb.Width = Unit.Percentage(100);

        container.Controls.Add(test);
        container.Controls.Add(tb);
    }
}//eof-class

Class reference for Unit

you can find unit methods here

Percentage: Creates a Unit of type Percentage from the specified double-precision floating-point number.

Pixel: Creates a Unit of type Pixel from the specified 32-bit signed integer.

Point: Creates a Unit of type Point from the specified 32-bit signed integer.


<asp:TemplateField HeaderText="Team Name" ItemStyle-Width="10%" >
   <ItemTemplate>
   <asp:Label ID="Label1" 
         Text='<%#getValue(Container.DataItem,"TEAM_NM") %>' 
      runat="server"/>
   </ItemTemplate>
</asp:TemplateField>

The absolute textboxes can mess up the percentage widths. I used a percentage width for the textbox so that it will take a percentage of the table column it is sitting in. with out this I saw the table not honoring the widths that are in the aspx page.