Hi All: I have a listview with a usercontrol in the itemTemplate and SelectedItemTemplate.
I need to pass some values to the usercontrol in the selectedItem template, but when I try to do it in the selectedIndexChanging event, the usercontrol doesn't display them. Am I passing the values to the usercontrol too early or too late in the page cycle?
Or do I need to do this in the itemdatabound event instead?
My selectedItem template looks like:
Ship To:
Bill To:
and in my codebehind:
Protected Sub lv_selecting(sender As Object, e As ListViewSelectEventArgs) Handles listView1.SelectedIndexChanging
Dim lvRow As ListViewItem = CType(listView1.Items(e.NewSelectedIndex), ListViewItem)
Dim ta As New dsReceiptTableAdapters.receiptTableAdapter
Dim dt As New dsReceipt.receiptDataTable
ta.Fill(dt, userID)
Dim addST As address = CType(lvRow.FindControl("addressST"), address)
Dim addBT As address = CType(lvRow.FindControl("addressBT"), address)
If dt.Rows.Count > 0 Then
addST.fName = dt(0).stFname
addST.lName = dt(0).stLname
addST.company = dt(0).stCompany
addST.add1 = dt(0).stAdd1
addST.add2 = dt(0).stAdd2
addST.city = dt(0).stCity
addST.state = dt(0).stState
addST.zip = dt(0).stZip
addST.country = dt(0).stCountry
addST.phone = dt(0).stPhone
addBT.fName = dt(0).btName
addBT.add1 = dt(0).btAdd1
addBT.city = dt(0).btCity
addBT.state = dt(0).btState
addBT.zip = dt(0).btZip
addBT.country = dt(0).btCountry
addBT.phone = dt(0).btPhone
End If
End Sub
hi,
you can give your usercontrol value in itemdatabound event , such as following .
Protected Sub ListView1_ItemDataBound(sender As Object, e As ListViewItemEventArgs)
If e.Item.ItemType = ListViewItemType.DataItem Then
Dim addST As address = CType(lvRow.FindControl("addressST"), address) Dim addBT As address = CType(lvRow.FindControl("addressBT"), address)
...
End If
End Sub
Hope this helps
沒有留言:
張貼留言