Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Controls / September 2007

Tip: Looking for answers? Try searching our database.

ObjectDataSource / MultiSelect ListBox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jay Pondy - 22 Sep 2007 18:40 GMT
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.
Jay Pondy - 22 Sep 2007 19:18 GMT
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("lstFavoriteColors"), ListBox)

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

       End If

   End Sub

>I have an ObjectDataSource bound to a Details View using a Custom Object.
>
[quoted text clipped - 32 lines]
>bound to the DetailsView so that I make the multi-select listbox reflect what is
>in the CustomObject.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.