0

I have two listboxes and i want to insert multiple selected values from both listboxes to database. Let me explain :-

<asp:ListBox ID="ddlSuperior" runat="server" SelectionMode="Multiple">
<asp:ListBox ID="ddlSubordinate" runat="server" SelectionMode="Multiple">

and a submit button

<asp:Button ID="btnSubmit" runat="server" Text="Submit" />

Suppose i select 2 values from ddlSuperior and 1 value from ddlSubordinate. How can i do that..?

David
  • 349
  • 3
  • 13
  • 26

1 Answers1

0

Well, there are quite a few ways.

    Dim superiorIndexes = ddlSuperior.GetSelectedIndices
    Dim vals = superiorIndexes.Select(Function(i) ddlSuperior.Items(i).Value)
    Dim subordinateIndexes = ddlSubordinate.GetSelectedIndices()

    vals = vals.Concat(subordinateIndexes.Select(Function(i) ddlSubordinate.Items(i).Value))

    For Each val As String In vals

        ' Code to do db insert

    Next

Find db example here: C# SQL insert command Look at Marc_S answer.

Community
  • 1
  • 1
Darthg8r
  • 12,377
  • 15
  • 63
  • 100