ASP.NET MVC ListBox - Get Selected Item


  • Alfreds FutterkisteALFKI
  • Antonio Moreno TaqueríaANATR
  • Around the HornAROUT
  • Berglunds snabbköpANTON
  • Berglunds snabbköpBERGS
  • Blauer See DelikatessenBLAUS
  • Blondesddsl père et filsBLONP
  • Bólido Comidas preparadasBOLID
  • Bon app'BONAP
  • Bottom-Dollar MarketsBOTTM
  • B's BeveragesBSBEV
  • Cactus Comidas para llevarCACTU
  • Centro comercial MoctezumaCENTC
  • Chop-suey ChineseCHOPS
  • Comércio MineiroCOMMI
  • Consolidated HoldingsCONSH
  • Die Wandernde KuhWANDK
  • Drachenblut DelikatessenDRACD
  • Du monde entierDUMON
  • Eastern ConnectionEASTC
  • Ernst HandelERNSH
  • Familia ArquibaldoFAMIA
  • FISSA Fabrica Inter. Salchichas S.A.FISSA
  • Folies gourmandesFOLIG
  • Folk och fä HBFOLKO
  • France restaurationFRANR
  • Franchi S.p.A.FRANS
  • FrankenversandFRANK
  • Furia Bacalhau e Frutos do MarFURIB
  • Galería del gastrónomoGALED
  • Godos Cocina TípicaGODOS
  • Gourmet LanchonetesGOURL
  • Great Lakes Food MarketGREAL
  • GROSELLA-RestauranteGROSR
  • Hanari CarnesHANAR
  • HILARION-AbastosHILAA
  • Hungry Coyote Import StoreHUNGC
  • Hungry Owl All-Night GrocersHUNGO
  • Island TradingISLAT
  • Königlich EssenKOENE
  • La corne d'abondanceLACOR
  • La maison d'AsieLAMAI
  • Laughing Bacchus Wine CellarsLAUGB
  • Lazy K Kountry StoreLAZYK
  • Lehmanns MarktstandLEHMS
  • Let's Stop N ShopLETSS
  • LILA-SupermercadoLILAS
  • LINO-DelicatesesLINOD
  • Lonesome Pine RestaurantLONEP
  • Magazzini Alimentari RiunitiMAGAA
  • Maison DeweyMAISD
  • Mère PaillardeMEREP
  • Morgenstern GesundkostMORGK
  • North/SouthNORTS
  • Océano Atlántico Ltda.OCEAN
  • Old World DelicatessenOLDWO
  • Ottilies KäseladenOTTIK
  • Paris spécialitésPARIS
  • Pericles Comidas clásicasPERIC
  • Piccolo und mehrPICCO
  • Princesa Isabel VinhosPRINI
  • Que DelíciaQUEDE
  • Queen CozinhaQUEEN
  • QUICK-StopQUICK
  • Rancho grandeRANCH
  • Rattlesnake Canyon GroceryRATTC
  • Reggiani CaseificiREGGC
  • Ricardo AdocicadosRICAR
  • Richter SupermarktRICSU
  • Romero y tomilloROMEY
  • Santé GourmetSANTG
  • Save-a-lot MarketsSAVEA
  • Seven Seas ImportsSEVES
  • Simons bistroSIMOB
  • Spécialités du mondeSPECD
  • Split Rail Beer & AleSPLIR
  • Suprêmes délicesSUPRD
  • The Big CheeseTHEBI
  • The Cracker BoxTHECR
  • Toms SpezialitätenTOMSP
  • Tortuga RestauranteTORTU
  • Tradição HipermercadosTRADH
  • Trail's Head Gourmet ProvisionersTRAIH
  • VaffeljernetVAFFE
  • Victuailles en stockVICTE
  • Vins et alcools ChevalierVINET
  • Wartian HerkkuWARTH
  • Wellington ImportadoraWELLI
  • White Clover MarketsWHITC
  • Wilman KalaWILMK
  • Wolski ZajazdWOLZA
  
Get Selected Item
Developers can retrieve information about the selected item using various variables available as parameters in the action method to which the form is posted:
  • [Name] - contains the selected value. Example: string ListBox1
  • [Name]_SelectedIndex - contains the selected index. Example: string ListBox1_SelectedIndex
  • [Name]_SelectedText - contains the selected text. Example: string ListBox1_SelectedText
View - Aspx

    <% Html.Obout(new ListBox("ListBox1")
    {   
        SelectionMode = ListBoxSelectionMode.Single
    }); %> 

    <% Html.Obout(new OboutButton("OboutButton1")
    {
        Text = "Get Selected Item"
    }); %> 
    
    
View - Razor

    @Html.Obout(new ListBox("ListBox1")
    {   
        SelectionMode = ListBoxSelectionMode.Single
    })

    @Html.Obout(new OboutButton("OboutButton1")
    {
        Text = "Get Selected Item"
    })
    
    
Controller

    public ViewResult SelectionSingleGet(string ListBox1, string ListBox1_SelectedIndex, 
    string ListBox1_SelectedText)
        {
            ViewData["ListBox1"] = GetCustomers();

            if (!string.IsNullOrEmpty(ListBox1))
            {
                string details = "<br /><br />";

                details += "<b>SelectedIndex</b>: " + ListBox1_SelectedIndex;
                details += "<br />";
                details += "<b>SelectedValue</b>: " + ListBox1;
                details += "<br />";
                details += "<b>SelectedText</b>: " + ListBox1_SelectedText;

                ViewData["Details"] = details;
            }

            return View();
        }