Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > ObjectDataSource / MultiSelect ListBox

Reply
Thread Tools

ObjectDataSource / MultiSelect ListBox

 
 
Jay Pondy
Guest
Posts: n/a
 
      09-22-2007
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.ObjectDataSourceMethodEv entArgs) Handles
dsEmployee.Inserting
e.InputParameters("FavoriteColors") = FavoriteColors()
End Sub

Protected Sub dsEmployee_Updating(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.ObjectDataSourceMethodEv entArgs) 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("lstFavoriteColo rs"), 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.
 
Reply With Quote
 
 
 
 
Jay Pondy
Guest
Posts: n/a
 
      09-22-2007
Try the DataBound event you dummy!

Protected Sub dvEmployee_DataBound(ByVal sender As Object, ByVal e As
System.EventArgs) Handles dvEmployee.DataBound

If dvEmployee.DataItem IsNot Nothing Then

Dim oEmployee As Employee = DirectCast(dvEmployee.DataItem,
Employee)
Dim lstColors As ListBox =
DirectCast(dvEmployee.FindControl("lstFavoriteColo rs"), ListBox)

For Each oItem As ListItem In lstColors.Items
oItem.Selected = Array.IndexOf(oEmployee.FavoriteColors,
oItem.Value) <> -1
Next


End If

End Sub


On Sat, 22 Sep 2007 13:40:56 -0400, Jay Pondy <(E-Mail Removed)> wrote:

>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.ObjectDataSourceMethodE ventArgs) Handles
>dsEmployee.Inserting
> e.InputParameters("FavoriteColors") = FavoriteColors()
> End Sub
>
> Protected Sub dsEmployee_Updating(ByVal sender As Object, ByVal e As
>System.Web.UI.WebControls.ObjectDataSourceMethodE ventArgs) 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("lstFavoriteCol ors"), 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Listbox Multiselect as filter for Gridview Nick Nelson ASP .Net Web Controls 8 08-24-2009 03:22 PM
multiselect dropdown JIK ASP .Net 4 05-13-2009 04:51 AM
Unexpected behaviour of Listbox MultiSelect Martin ASP .Net Web Controls 5 01-24-2006 08:15 AM
Multiselect listbox jumps to top on postback Lenard Gunda ASP .Net 3 08-17-2005 04:29 PM
How can I use a multiselect listbox to pass parameter to a SQL SP Jeff Thur ASP .Net Web Controls 2 02-14-2005 02:01 PM



Advertisments