ASP.NET DataTable output problem
I can't for the life of me work out what I am doing wrong here, despite much searching on SO/Google.

Basically I have a simple DataTable which is held in ViewState and adjusted during postbacks. When I try to write out the values, it is just an empty string. Please find below an abbreviated example of what I have - the output in this case just winds up as a string of apostrophes (one for each execution) so it looks as though the rows are being added, but the ("Product") column is empty. 

Thanks for your help.

        Dim dtItems As New DataTable
        If ViewState("Items") Is Nothing Then
            Dim dcColumn As DataColumn
            dcColumn = New DataColumn()
            dcColumn.DataType = Type.GetType("System.String")
            dcColumn.ColumnName = "Product"
            dtItems.Columns.Add(dcColumn)
            ViewState("Items") = dtItems
        End If
        dtItems = CType(ViewState("Items"), DataTable)
        Dim drRow As DataRow
        drRow = dtItems.NewRow()
        drRow("Product") = "The Product"
        dtItems.Rows.Add()
        For Each drRow In dtItems.Rows
            txtTestDT.Text += drRow(("Product")).ToString & "!"
        Next

 


ASP.NET DataTable output problem
===

I can't for the life of me work out what I am doing wrong here, despite much searching on SO/Google.

Basically I have a simple DataTable which is held in ViewState and adjusted during postbacks. When I try to write out the values, it is just an empty string. Please find below an abbreviated example of what I have - the output in this case just winds up as a string of apostrophes (one for each execution) so it looks as though the rows are being added, but the ("Product") column is empty. 

Thanks for your help.

        Dim dtItems As New DataTable
        If ViewState("Items") Is Nothing Then
            Dim dcColumn As DataColumn
            dcColumn = New DataColumn()
            dcColumn.DataType = Type.GetType("System.String")
            dcColumn.ColumnName = "Product"
            dtItems.Columns.Add(dcColumn)
            ViewState("Items") = dtItems
        End If
        dtItems = CType(ViewState("Items"), DataTable)
        Dim drRow As DataRow
        drRow = dtItems.NewRow()
        drRow("Product") = "The Product"
        dtItems.Rows.Add()
        For Each drRow In dtItems.Rows
            txtTestDT.Text += drRow(("Product")).ToString & "!"
        Next

 

