Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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:

 

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

The three most important things in life: God, your family, and the Green Bay Packers -- Not necessarily in that order.

Winning is not a sometime thing. You don't win once in a while, you don't do things right once in a while, you do them right all the time. Winning is a habit. Unfortunately, so is losing.

-- Vincent T. Lombardi

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...