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..?

4
  • What's the problem, what have you tried? Commented Jan 15, 2013 at 13:43
  • On submit button click, i want to insert - 2 selected values from ddlSuperior and 1 selected value from ddlSubordinate to a database 'tblPosition' with columns - id,superior and subordinate. Commented Jan 15, 2013 at 13:54
  • It means one id has two superiors and one subordinate Commented Jan 15, 2013 at 13:55
  • You have one column for superior but the user must select two? I would suggest to add another superior column then. Commented Jan 15, 2013 at 13:57

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.