J
Jay Pondy
I have an ObjectDataSource bound to a Details View using a Custom Object.
The DetailsView contains a multi-select listbox. I have been able to get the
selected items from the listbox into a string array and pass the array to the
insert and update parameters successfully as follows:
Protected Sub dsEmployee_Inserting(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs) Handles
dsEmployee.Inserting
e.InputParameters("FavoriteColors") = FavoriteColors()
End Sub
Protected Sub dsEmployee_Updating(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs) Handles
dsEmployee.Updating
e.InputParameters("FavoriteColors") = FavoriteColors()
End Sub
Private Function FavoriteColors() As String()
'Convert the selected colors in the ListBox to a string array
Dim lstColors As ListBox =
DirectCast(dvEmployee.FindControl("lstFavoriteColors"), ListBox)
Dim aColors As New ArrayList
For Each oItem As ListItem In lstColors.Items
If oItem.Selected Then aColors.Add(oItem.Value)
Next
Return aColors.ToArray(Type.GetType("System.String"))
End Function
What I can't seem to figure out is how can I access my CustomObject when it gets
bound to the DetailsView so that I make the multi-select listbox reflect what is
in the CustomObject.
The DetailsView contains a multi-select listbox. I have been able to get the
selected items from the listbox into a string array and pass the array to the
insert and update parameters successfully as follows:
Protected Sub dsEmployee_Inserting(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs) Handles
dsEmployee.Inserting
e.InputParameters("FavoriteColors") = FavoriteColors()
End Sub
Protected Sub dsEmployee_Updating(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs) Handles
dsEmployee.Updating
e.InputParameters("FavoriteColors") = FavoriteColors()
End Sub
Private Function FavoriteColors() As String()
'Convert the selected colors in the ListBox to a string array
Dim lstColors As ListBox =
DirectCast(dvEmployee.FindControl("lstFavoriteColors"), ListBox)
Dim aColors As New ArrayList
For Each oItem As ListItem In lstColors.Items
If oItem.Selected Then aColors.Add(oItem.Value)
Next
Return aColors.ToArray(Type.GetType("System.String"))
End Function
What I can't seem to figure out is how can I access my CustomObject when it gets
bound to the DetailsView so that I make the multi-select listbox reflect what is
in the CustomObject.