A
Angel
I want to add a directive to a Template Column that I created at runtime
using the following code:
Sub CreateColumn()
Dim tc1 As New TemplateColumn
tc1.HeaderTemplate = New DataGridTemplate(ListItemType.Header,
"TEST")
tc1.ItemStyle.CssClass = "datagridcell"
tc1.ItemStyle.Width = New Unit("100%")
tc1.ItemTemplate = New DataGridTemplate(ListItemType.Item, "TEST")
grid.columns.add(tc1)
End Sub
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
Select Case templateType
Case ListItemType.Header
lc.Text = "<B><NOBR>" & columnName & "</NOBR></B>"
container.Controls.Add(lc)
Case ListItemType.Item
'container.Controls.Add(lc)
Dim lb As New System.Web.UI.WebControls.Label
lb.ID = "lbl" & columnName.Trim
lb.Text = "<%#
GetBucketCount(Container.DataItem(''strCount''), 0)%>"
container.Controls.Add(lb)
End Select
End Sub
End Class
As you can see from the code I want to add the following directive:
<%# GetBucketCount(Container.DataItem(''strCount''), 0)%>
So when the WebGrid is bound with its data(grid.dataBind) it formats the
column correctly. The problem that I am having with the code it does not fill
in the data called by the directive. Does anyone has any thoughts on how to
set a directive to a dynamically created web grid column.
thanks in advance.
using the following code:
Sub CreateColumn()
Dim tc1 As New TemplateColumn
tc1.HeaderTemplate = New DataGridTemplate(ListItemType.Header,
"TEST")
tc1.ItemStyle.CssClass = "datagridcell"
tc1.ItemStyle.Width = New Unit("100%")
tc1.ItemTemplate = New DataGridTemplate(ListItemType.Item, "TEST")
grid.columns.add(tc1)
End Sub
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
Select Case templateType
Case ListItemType.Header
lc.Text = "<B><NOBR>" & columnName & "</NOBR></B>"
container.Controls.Add(lc)
Case ListItemType.Item
'container.Controls.Add(lc)
Dim lb As New System.Web.UI.WebControls.Label
lb.ID = "lbl" & columnName.Trim
lb.Text = "<%#
GetBucketCount(Container.DataItem(''strCount''), 0)%>"
container.Controls.Add(lb)
End Select
End Sub
End Class
As you can see from the code I want to add the following directive:
<%# GetBucketCount(Container.DataItem(''strCount''), 0)%>
So when the WebGrid is bound with its data(grid.dataBind) it formats the
column correctly. The problem that I am having with the code it does not fill
in the data called by the directive. Does anyone has any thoughts on how to
set a directive to a dynamically created web grid column.
thanks in advance.