Hello,
i add template column to datagrid.
Code Of template column:
VB Code:
Private Class DataGridTemplate Implements ITemplate Dim templateType As ListItemType Dim columnName As String Dim type As Int16 Sub New(ByVal lstType As ListItemType, ByVal ColName As String, ByVal colType As Int16) templateType = lstType columnName = ColName type = colType End Sub Sub InstantiateIn(ByVal container As Control) _ Implements ITemplate.InstantiateIn Select Case type Case 0 Dim lc As New Literal Select Case templateType Case ListItemType.Header lc.Text = "<B>" & columnName & "</B>" container.Controls.Add(lc) Case ListItemType.Item lc.Text = columnName AddHandler lc.DataBinding, AddressOf DataGridTemplate_DataBinding container.Controls.Add(lc) Case ListItemType.EditItem Dim tb As New TextBox tb.Text = "" tb.ID = columnName container.Controls.Add(tb) Case ListItemType.Footer lc.Text = "<I>Footer</I>" container.Controls.Add(lc) End Select End Select End Sub Private Sub DataGridTemplate_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs) Dim container As DataGridItem Dim lc As Literal lc = CType(sender, Literal) container = CType(lc.NamingContainer, DataGridItem) If Not IsDBNull(DataBinder.Eval(container.DataItem, lc.Text)) Then lc.Text = DataBinder.Eval(container.DataItem, lc.Text) End If End Sub End Class End Class
If column name is "Text(20)" then I got error:
If I remove "(" and ")" from column name then this code works fine.Code:DataBinder.Eval: 'System.Data.DataRowView' does not contain a property with the name "Text"
How to solve this problem?


Reply With Quote