Unable to display child rows

G

Guest

I created a dropdown list and a datagrid in a webform. When a customer's name
is selected in the dropdown list, a "SelectedIndexChanged" event is raised
and the orders for that customer would be displayed in the datagrid.

The following code was written but the orders were not displayed after a
customer is selected from the dropdown list. Anyone knows what's wrong ?
************************************************
Private Sub lstCustomer_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles lstCustomer.SelectedIndexChanged
Dim drNew As New DataRelation("CustOrders",
ds.Tables("Customers").Columns("CustomerID"),
ds.Tables("Orders").Columns("CustomerID"))
Dim strCurrent As String = lstCustomer.SelectedItem.Value
Dim dvCustOrders As New DataView(ds.Tables("Customers"))
Dim drView As DataRowView

dvCustOrders = drView.CreateChildView(drNew)
dvCustOrders.RowFilter = "CustomerID='" & strCurrent & "'"
dgCustOrders.DataSource = dvCustOrders
dgCustOrders.DataBind()

End Sub
 
C

Cor Ligthert

Kim,

You are using here two methods in each other.

I would change this in your situation (Where I assume that you have in your
loadform in the postback have placed back your saved dataset n the ds)
Private Sub lstCustomer_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles lstCustomer.SelectedIndexChanged
Dim drNew As New DataRelation("CustOrders",
ds.Tables("Customers").Columns("CustomerID"),
ds.Tables("Orders").Columns("CustomerID"))
'Remove the DrNew
Dim strCurrent As String = lstCustomer.SelectedItem.Value
Dim dvCustOrders As New DataView(ds.Tables("Customers"))
'Change the row above in
Dim dvCustOrders As New DataView(ds.Tables("Orders"))

Dim drView As DataRowView
dvCustOrders = drView.CreateChildView(drNew)
'Remove the rows above
dvCustOrders.RowFilter = "CustomerID='" & strCurrent & "'"
dgCustOrders.DataSource = dvCustOrders
dgCustOrders.DataBind()

End Sub

All done in this message not tested,

I hope this helps,

Cor
 
G

Guest

Tried your method but has no effect.

Cor Ligthert said:
Kim,

You are using here two methods in each other.

I would change this in your situation (Where I assume that you have in your
loadform in the postback have placed back your saved dataset n the ds)

'Remove the DrNew

'Change the row above in
Dim dvCustOrders As New DataView(ds.Tables("Orders"))


'Remove the rows above


All done in this message not tested,

I hope this helps,

Cor
 
C

Cor Ligthert

Kim,

You are sure as I wrote that the dataset is reinstalled again at postback?

(And that there is postback)

Cor
 
G

Guest

Pardon me if I don't quite understand your first email.

Are you saying that I should include a statement as below ?

<< Private Sub lstCustomer_SelectedIndexChanged(...)...
if Page.IsPostBack then
Dim strCurrent As String =
lstCustomer.SelectedItem.Value
Dim dvCustOrders As New DataView(ds.Tables("Orders"))

dvCustOrders.RowFilter = "CustomerID='" & strCurrent
& "'"
dgCustOrders.DataSource = dvCustOrders
dgCustOrders.DataBind()
End If
End Sub
There is error thrown.
 
C

Cor Ligthert

Kim

A webform is not persistent, that means that you have to save it while it is
sent.

Something as to save it
session.item("dataset") = ds

And on postback
ds = session.item("dataset")

I hope this helps,

Cor
 
G

Guest

I've tried creating a Session object to store the dataset that was loaded
during the first request and then retrieve it into the same dataset when the
page was posted back when a selectedIndex changed. This concept failed to
work.

How can I correct this ?
____________________________________
Private Sub Page_Load(...) Handles ...
If Not Page.IsPostBack then
'Fill ds dataset
Session.item("dsMaster") = ds
'databind the controls to ds
Else
ds = Session.item("dsMaster")
End if
End Sub
_______________________________
 
C

Cor Ligthert

Kim,

I miss by instance the ones inline in the code (don't do the "databind" in
the postback portion of this, that you do when you have changed things)
____________________________________
Private Sub Page_Load(...) Handles ...
If Not Page.IsPostBack then
'Fill ds dataset
Session.item("dsMaster") = ds datagrid.datasource = ds
'databind the controls to ds
Else
ds = Session.item("dsMaster") datagrid.datasource = ds
End if
End Sub
_______________________________
I hope this helps,

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top