troubleshooting Question

databinding gridView

Avatar of ARACK04
ARACK04 asked on
ASP.NET
9 Comments1 Solution658 ViewsLast Modified:
When I bind a DataTable to a GridView, I am not seeing any data, but instead System.Data.DataRow in each row of the GridView.  Here is the code:

Here is a GridView:
        <asp:GridView ID="dg2" runat="server" Width="880px" AutoGenerateColumns="false"><Columns>            
                <asp:BoundField DataField="Division" HeaderText="Division" ItemStyle-Width="150px" />
                <asp:BoundField DataField="Status" HeaderText="Status" ItemStyle-Width="125px" ItemStyle-Wrap="true" />
                <asp:BoundField DataField="Total_Value" DataFormatString="{0:C}" HeaderText="Total Value" >
        </Columns></asp:GridView>

And here is how it gets bound

        dtTable = New DataTable()

        newCol = New DataColumn("Status")
        newCol.DataType = System.Type.GetType("System.String")
        dtTable.Columns.Add(newCol)

        newCol = New DataColumn("Division")
        newCol.DataType = System.Type.GetType("System.String")
        dtTable.Columns.Add(newCol)

        newCol = New DataColumn("Total_Value")
        newCol.DataType = System.Type.GetType("System.Double")
        dtTable.Columns.Add(newCol)

        'eventually this will be more complex, obviously
        For Each key In myKeys            
            row("Division") = "hello"
            row("Status") = "world"
            row("Total_Value") = 4.5

            dtTable.Rows.Add(row)
        Next

        dg2.DataSource = dtTable
        dg2.DataBind()
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 9 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros