Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
|
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 1st, 2012, 06:20 PM
Registered User
 
Join Date: Dec 2011
Posts: 2
Thanks: 3
Thanked 0 Times in 0 Posts
Smile getting ListBox to behave like DropDownList

Hi All
I'm using VS Pro 2010 and have worked through Chapter 13 in the book. My experience is mostly in PHP.

My question is this: how do I get the ListBox control in my DetailsView to behave like the DropDownList did in the Chapter 13 exercises.

I actually do have it working, but I want its SelectionMode to be "Multiple". When I use it now only the first selection is inserted into the database.

Ultimately (after I learn a lot more) I'd like to do everything properly and have those multiple selections insert into a different table (one-to-many) but for now I would be happy settling for a comma-separated string (ie: "blue,red,white").

I thought I was on the right track writing some code in the DetailsView1_ItemInserting subroutine, but I can't seem to be able to access my ListBox control in order to loop through it.

If anyone can point me in the right direction that would be awesome!
 
Old January 2nd, 2012, 07:58 PM
Registered User
 
Join Date: Dec 2011
Posts: 2
Thanks: 3
Thanked 0 Times in 0 Posts
Lightbulb Figured it out

Well I think I figured it out!

Code:
    Protected Sub DetailsView1_ItemInserting(sender As Object, e As System.Web.UI.WebControls.DetailsViewInsertEventArgs) Handles DetailsView1.ItemInserting

        Dim myListBox As ListBox
        myListBox = DetailsView1.FindControl("ListBox1")
        Dim myEthnicity As String = ""
        Dim Item As ListItem

        For Each Item In myListBox.Items
            If Item.Selected Then
                myEthnicity += Item.Text & ", "
            End If
        Next

        e.Values("Ethnicity") = myEthnicity

    End Sub





Similar Threads
Thread Thread Starter Forum Replies Last Post
DropDownList/CheckboxList/RadioboxList or Listbox "selections" to Response Email tompatamcat BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 September 6th, 2010 03:43 PM
multiple Listbox values in another listbox terryv Excel VBA 0 June 27th, 2007 07:01 AM
when does extends and interfaces behave the same austinf Pro Java 2 September 11th, 2006 07:04 AM
POST method behave strangely laxenai Beginning PHP 1 May 4th, 2004 12:23 PM
I'm back :) Listbox var from listbox MichaelTJ .NET Web Services 2 October 21st, 2003 07:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.