Hello Everyone,
I have been successful in creating a template column programatically using
the examples provided in VS 2003.
However I have not been able to programatically set the width of a template
column programatically
Here is the code that I have used so far
Private Class DataGridTemplate
Implements ITemplate
Dim templateType As ListItemType
Dim columnName As String
Sub New(ByVal type As ListItemType, ByVal ColName As String)
templateType = type
columnName = ColName
End Sub
Sub InstantiateIn(ByVal container As Control) _
Implements ITemplate.InstantiateIn
Dim lc As New Literal
Dim txt As New TextBox
Select Case templateType
Case ListItemType.Header
lc.Text = "<B>" & columnName & "</B>"
container.Controls.Add(lc)
Case ListItemType.Item
txt.ID = columnName
txt.Font.Name = "Verdana"
txt.Font.Size = FontUnit.XXSmall
txt.Font.Bold = True
txt.Columns = 10
txt.Width = Unit.Percentage(5)
container.Controls.Add(txt)
End Select
End Sub
End Class
And here is the code that calls the class
Dim columnlist As New SortedList
columnlist.Clear()
Dim row As DataRow
For Each row In ds.Tables("AllLevel3AttributesForLevel4").Rows
Dim tempcol As New TemplateColumn
tempcol.HeaderTemplate = New
DataGridTemplate(ListItemType.Header, row("AttributeCode").ToString)
tempcol.ItemTemplate = New DataGridTemplate(ListItemType.Item,
row("AttributeCode").ToString)
grdKeysGenerated.Columns.Add(tempcol)
columnlist.Add(row("AttributeId").ToString,
row("AttributeCode").ToString)
Next
' Save into session the list of columns (attributes) for this level 4
Session("ColumnList") = columnlist
If ds.Tables("AllDatakeys").Rows.Count > 0 Then
With grdKeysGenerated
.DataSource = ds.Tables("AllDataKeys")
.DataBind()
End With
End If
Is there any way to programatically set the new columns i have created to
have widths of 5% (or lets say 50px)?
Thanks in advance
Corey