SteveoAtilla
Well-known member
Now Ive got a new problem with this project. I have a datagrid bound to a datatable I created in the form designer. Im 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.
Heres the code:
I stop the code at the end if to debug, and heres 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.
Whats wrong with this code???? I cant find it. It seems like the second time, Im not getting the "real" table back from the ViewState, and that is the table that is bound to the datagrid, despite the fact that Im setting it in code.
HELP!!!
Kahuna
Heres 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 heres 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.
Whats wrong with this code???? I cant find it. It seems like the second time, Im not getting the "real" table back from the ViewState, and that is the table that is bound to the datagrid, despite the fact that Im setting it in code.
HELP!!!
Kahuna