T
trebor
Most of this code comes from or follows the walkthrough (Using a
DataGrid Web Control to Read and Write Data). The problem is that as
soon as you click the Edit link, the data rows disappear, leaving you
with just the header row. I've figured out what's happening, but can't
figure out why.
Following along with the debugger, as soon as you click Edit, execution
goes to Page_Load, and at that point, before it even checks postback,
the dataset is empty. All the rows are gone. Anyone know why?
I suppose I could refill the dataset in Page_Load, but that leads to the
dreaded "Old Values" problem.
This doesn't make sense! Why would the bottom fall out of the dataset?
The structure is still there, all the column names and everything, but
the data itself is gone -- rows.count returns 0.
Thanks for any help!
Private Sub Page_Load(ByVal sender As System.Object, ByVal e ...
If Not Page.IsPostBack Then
OleDbDataAdapter1.Fill(myDataSet1)
DataGrid1.DataBind()
End If
End Sub
Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e ...
DataGrid1.EditItemIndex = e.Item.ItemIndex
DataGrid1.DataBind()
End Sub
Private Sub DataGrid1_CancelCommand(ByVal source As Object, ByVal e...
DataGrid1.EditItemIndex = -1
DataGrid1.DataBind()
End Sub
Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e...
Dim key As String = DataGrid1.DataKeys(e.Item.ItemIndex).ToString()
Dim strA, strB, strC As String
Dim txt As TextBox
txt = CType(e.Item.Cells(1).Controls(0), TextBox)
strA = txt.Text
txt = CType(e.Item.Cells(2).Controls(0), TextBox)
strB = txt.Text
txt = CType(e.Item.Cells(3).Controls(0), TextBox)
strC = txt.Text
Dim r As myDataSet.XRow
r = myDataSet1.X.FindByRecID(key)
r.A = strA
r.B = strB
r.C = strC
OleDbDataAdapter1.Update(myDataSet1)
DataGrid1.EditItemIndex = -1
DataGrid1.DataBind()
End Sub
End Class
DataGrid Web Control to Read and Write Data). The problem is that as
soon as you click the Edit link, the data rows disappear, leaving you
with just the header row. I've figured out what's happening, but can't
figure out why.
Following along with the debugger, as soon as you click Edit, execution
goes to Page_Load, and at that point, before it even checks postback,
the dataset is empty. All the rows are gone. Anyone know why?
I suppose I could refill the dataset in Page_Load, but that leads to the
dreaded "Old Values" problem.
This doesn't make sense! Why would the bottom fall out of the dataset?
The structure is still there, all the column names and everything, but
the data itself is gone -- rows.count returns 0.
Thanks for any help!
Private Sub Page_Load(ByVal sender As System.Object, ByVal e ...
If Not Page.IsPostBack Then
OleDbDataAdapter1.Fill(myDataSet1)
DataGrid1.DataBind()
End If
End Sub
Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e ...
DataGrid1.EditItemIndex = e.Item.ItemIndex
DataGrid1.DataBind()
End Sub
Private Sub DataGrid1_CancelCommand(ByVal source As Object, ByVal e...
DataGrid1.EditItemIndex = -1
DataGrid1.DataBind()
End Sub
Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e...
Dim key As String = DataGrid1.DataKeys(e.Item.ItemIndex).ToString()
Dim strA, strB, strC As String
Dim txt As TextBox
txt = CType(e.Item.Cells(1).Controls(0), TextBox)
strA = txt.Text
txt = CType(e.Item.Cells(2).Controls(0), TextBox)
strB = txt.Text
txt = CType(e.Item.Cells(3).Controls(0), TextBox)
strC = txt.Text
Dim r As myDataSet.XRow
r = myDataSet1.X.FindByRecID(key)
r.A = strA
r.B = strB
r.C = strC
OleDbDataAdapter1.Update(myDataSet1)
DataGrid1.EditItemIndex = -1
DataGrid1.DataBind()
End Sub
End Class