Results 1 to 2 of 2

Thread: DataBinding in Template column error

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2000
    Location
    Europe, Lithuania
    Posts
    309

    Unhappy DataBinding in Template column error

    Hello,

    i add template column to datagrid.

    Code Of template column:

    VB Code:
    1. Private Class DataGridTemplate
    2.             Implements ITemplate
    3.             Dim templateType As ListItemType
    4.             Dim columnName As String
    5.             Dim type As Int16
    6.             Sub New(ByVal lstType As ListItemType, ByVal ColName As String, ByVal colType As Int16)
    7.                 templateType = lstType
    8.                 columnName = ColName
    9.                 type = colType
    10.             End Sub
    11.  
    12.             Sub InstantiateIn(ByVal container As Control) _
    13.                Implements ITemplate.InstantiateIn
    14.  
    15.                 Select Case type
    16.  
    17.  
    18.                     Case 0
    19.                         Dim lc As New Literal
    20.                         Select Case templateType
    21.                             Case ListItemType.Header
    22.                                 lc.Text = "<B>" & columnName & "</B>"
    23.                                 container.Controls.Add(lc)
    24.                             Case ListItemType.Item
    25.                                 lc.Text = columnName
    26.                                 AddHandler lc.DataBinding, AddressOf DataGridTemplate_DataBinding
    27.                                 container.Controls.Add(lc)
    28.                             Case ListItemType.EditItem
    29.                                 Dim tb As New TextBox
    30.                                 tb.Text = ""
    31.                                 tb.ID = columnName
    32.                                 container.Controls.Add(tb)
    33.                             Case ListItemType.Footer
    34.                                 lc.Text = "<I>Footer</I>"
    35.                                 container.Controls.Add(lc)
    36.                         End Select
    37.  
    38.  
    39.                 End Select
    40.             End Sub
    41.  
    42.             Private Sub DataGridTemplate_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs)
    43.                 Dim container As DataGridItem
    44.                 Dim lc As Literal
    45.  
    46.                 lc = CType(sender, Literal)
    47.                 container = CType(lc.NamingContainer, DataGridItem)
    48.                 If Not IsDBNull(DataBinder.Eval(container.DataItem, lc.Text)) Then
    49.                     lc.Text = DataBinder.Eval(container.DataItem, lc.Text)
    50.                 End If
    51.  
    52.             End Sub
    53.  
    54.         End Class
    55.  
    56.     End Class

    If column name is "Text(20)" then I got error:
    Code:
    DataBinder.Eval: 'System.Data.DataRowView' does not contain a property with the name "Text"
    If I remove "(" and ")" from column name then this code works fine.

    How to solve this problem?

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2000
    Location
    Europe, Lithuania
    Posts
    309

    Re: DataBinding in Template column error

    I have changed to this:

    VB Code:
    1. If Not IsDBNull(container.DataItem(lc.Text)) Then
    2.                     lc.Text = container.DataItem(lc.Text)
    3.                 End If

    Interesting why error ecured in previous code...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width