Datagrid not displaying rows in the bound table...

SteveoAtilla

Regular
Joined
Dec 22, 2004
Messages
80
Location
The Frozen Tundra
Now I've got a new problem with this project. I have a datagrid bound to a datatable I created in the form designer. I'm adding rows to the data table in code, and the first time I bind the datagrid, it shows one row, and the second and subsequent times I bind it, it shows 0 rows, but DOES show the header.

Here's the code:

Code:
 Dim PartNumber As String
 Dim GoodPart As Boolean
 Dim PartCount As Integer = Session("PartCount")
 Dim PartIndex As Integer = Session("PartIndex")
 Dim PartLine As String = ""
 Dim dtParts As DataTable
 Dim dtCopy As DataTable
 
 If Session("PostBack") = True Then
   Session("PostBack") = False
   dtParts = dsSelectedParts.Tables("dtSelectedParts")
 Else
   dtParts = ViewState("PartsTable")
 End If
 
 If Len(Trim(txtPartNum.Text)) > 0 Then
   PartNumber = UCase(txtPartNum.Text)
   GoodPart = ValidPart(PartNumber)
 Else
   GoodPart = False
 End If
 
 If GoodPart Then
   Dim NewTableRow As DataRow
   NewTableRow = dtParts.NewRow()
   NewTableRow("RowID") = PartIndex
   NewTableRow("PartNumber") = Session("PartNum")
   NewTableRow("PartDesc") = Session("PartDesc")
   NewTableRow("PartMBS") = Session("PartMBS")
   NewTableRow("PartRev") = Session("PartRev")
   NewTableRow("PartDwg") = Session("PartDwg")
 
   dtParts.Rows.Add(NewTableRow)
   dtParts.AcceptChanges()
   dtCopy = dtParts.Copy()
 
   ViewState("PartsTable") = dtCopy
 
   Dim dtSelCount As Integer = dsSelectedParts.Tables("dtSelectedParts").Rows.Count
   Dim dtCount As Integer = dtParts.Rows.Count
   dgSelectedParts.DataSource = dtParts
   dgSelectedParts.SelectedIndex = -1
   dgSelectedParts.DataBind()
   Dim dgCount As Integer = dgSelectedParts.Items.Count
 End If

I stop the code at the end if to debug, and here's what I get:

The FIRST time, dtSelCount is 1, dtCount is 1, and dgCount is 1.
The SECOND time, dtSelCount is 0, dtCount is 2, and dgCount is 0.

What's wrong with this code???? I can't find it. It seems like the second time, I'm not getting the "real" table back from the ViewState, and that is the table that is bound to the datagrid, despite the fact that I'm setting it in code.

HELP!!!

Kahuna
 
Back
Top