Groups | Blog | Home
all groups > dotnet datatools > december 2004 >

dotnet datatools : ASP Table doe not hold state


Fire-Dog
12/22/2004 9:23:06 AM
I am trying to update an ASP table on a round trip or post back to the
server. The problem is that the first time I post back to the server I add a
row the table and the result is displayed to the client. On the second post
back I am trying to add another row but that row only replaces the row that I
added on the first post back.

After the second post back I was expecting to see two rows in the table.
Can anyone tell me why this happens and how I can accomplish this with out
having to go all the way around the world to get there? If it helps the code
is included below

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
Dim li As ListItem
For i As Integer = 1 To 10
li = New ListItem
li.Text = i & " - Prod"
li.Value = i & " - id"
DropDownList1.Items.Add(li)
Next
End If

End Sub

Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
DropDownList1.SelectedIndexChanged
Dim oCell As TableCell
Dim oRow As New TableRow

For i As Integer = 0 To 3
oCell = New TableCell
Select Case i
Case 0
oCell.Text = DropDownList1.SelectedItem.Value

Case 1
oCell.Text = DropDownList1.SelectedItem.Text

Case 2
oCell.Text = "Bla bla bla"

Case 3
oCell.Controls.Add(New CheckBox)
End Select

oRow.Cells.Add(oCell)
Next

Table1.Rows.Add(oRow)

End Sub
End Class
NJB
1/11/2005 12:51:04 PM
Is Table1 a server control? If so, do you have ViewStateEnabled set to true?

[quoted text, click to view]
Fire-Dog
1/11/2005 5:09:02 PM
yes Table1 is a server control and ViewStateEnabled is set to true.

[quoted text, click to view]
AddThis Social Bookmark Button