Home All Groups Group Topic Archive Search About

Issue getting value from dynamically creating datagrid boundcolumn

Author
24 Aug 2006 6:41 PM
Erik
Good Afternoon,
I am dynamically creating boundcolumns for a datagrid during the databinding
event.  Everything is rendered properly, but I am unable to get the value of
the boundcolumn.  The count for the datagridrow cells is only returning 1,
which is the static templatecolumn.
Any suggestions / insights on why I can't retrieve the values of the
boundcolumns is greatly appreciated. 
Below is the code building the boundcolumns.
Thanks, Erik

    Private Sub dgrdEquip_DataBinding(ByVal sender As Object, ByVal e As
System.EventArgs) Handles dgrdEquip.DataBinding
        'During the databinding we will loop through the columns on the
datatable
        'and build a tempalte column that has one imagebutton in it
        'add it to the grid.columns collection then
        'create another boundcolumn that would display the value in the column

        Dim tbl As DataTable = dstEquipInv.Tables("EquipInv")
        If tbl.Rows.Count <> 0 Then
            Dim dc As DataColumn

            For Each dc In tbl.Columns

                    Dim bc As New BoundColumn   'add a column to contain the
value of the field
                    bc.DataField = dc.ColumnName
                    bc.HeaderText = dc.ColumnName
                    bc.HeaderStyle.CssClass = "TDHeader"
                    bc.SortExpression = dc.ColumnName

                    bc.ItemStyle.CssClass = "TDItem"

                    CType(sender, DataGrid).Columns.Add(bc)
                End If
            Next
        End If
    End Sub