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 DataGridTemplat e
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(B yVal container As Control) _
Implements ITemplate.Insta ntiateIn
Dim lc As New Literal
Dim txt As New TextBox
Select Case templateType
Case ListItemType.He ader
lc.Text = "<B>" & columnName & "</B>"
container.Contr ols.Add(lc)
Case ListItemType.It em
txt.ID = columnName
txt.Font.Name = "Verdana"
txt.Font.Size = FontUnit.XXSmal l
txt.Font.Bold = True
txt.Columns = 10
txt.Width = Unit.Percentage (5)
container.Contr ols.Add(txt)
End Select
End Sub
End Class
And here is the code that calls the class
Dim columnlist As New SortedList
columnlist.Clea r()
Dim row As DataRow
For Each row In ds.Tables("AllL evel3Attributes ForLevel4").Row s
Dim tempcol As New TemplateColumn
tempcol.HeaderT emplate = New
DataGridTemplat e(ListItemType. Header, row("AttributeC ode").ToString )
tempcol.ItemTem plate = New DataGridTemplat e(ListItemType. Item,
row("AttributeC ode").ToString )
grdKeysGenerate d.Columns.Add(t empcol)
columnlist.Add( row("AttributeI d").ToString ,
row("AttributeC ode").ToString )
Next
' Save into session the list of columns (attributes) for this level 4
Session("Column List") = columnlist
If ds.Tables("AllD atakeys").Rows. Count > 0 Then
With grdKeysGenerate d
.DataSource = ds.Tables("AllD ataKeys")
.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
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 DataGridTemplat e
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(B yVal container As Control) _
Implements ITemplate.Insta ntiateIn
Dim lc As New Literal
Dim txt As New TextBox
Select Case templateType
Case ListItemType.He ader
lc.Text = "<B>" & columnName & "</B>"
container.Contr ols.Add(lc)
Case ListItemType.It em
txt.ID = columnName
txt.Font.Name = "Verdana"
txt.Font.Size = FontUnit.XXSmal l
txt.Font.Bold = True
txt.Columns = 10
txt.Width = Unit.Percentage (5)
container.Contr ols.Add(txt)
End Select
End Sub
End Class
And here is the code that calls the class
Dim columnlist As New SortedList
columnlist.Clea r()
Dim row As DataRow
For Each row In ds.Tables("AllL evel3Attributes ForLevel4").Row s
Dim tempcol As New TemplateColumn
tempcol.HeaderT emplate = New
DataGridTemplat e(ListItemType. Header, row("AttributeC ode").ToString )
tempcol.ItemTem plate = New DataGridTemplat e(ListItemType. Item,
row("AttributeC ode").ToString )
grdKeysGenerate d.Columns.Add(t empcol)
columnlist.Add( row("AttributeI d").ToString ,
row("AttributeC ode").ToString )
Next
' Save into session the list of columns (attributes) for this level 4
Session("Column List") = columnlist
If ds.Tables("AllD atakeys").Rows. Count > 0 Then
With grdKeysGenerate d
.DataSource = ds.Tables("AllD ataKeys")
.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