Get multiple selected values from Listbox in - ASPMANTRA | Asp.Net,MVC,AngularJs,Jquery,Javascript,Sql Server AND WCF snippets and tutorial

Get multiple selected values from Listbox in

Introduction: In this article today I am going to explain how we can get multiple selected values from Listbox in

Design the webform as given below:
  <fieldset style="width:450px">
    <legend>Listbox Example</legend> 
    Country :
<asp:ListBox ID="lstcountry" runat="server" Width="100px" SelectionMode="Multiple">
        <br /> 
        <br />
            ID="btnsubmit" runat="server" Text="Get Value" onclick="btnsubmit_Click" /> 
        <asp:Label ID="lblmessage" runat="server"></asp:Label> 

On button click write the below given code (C#):
  protected void btnsubmit_Click(object sender, EventArgs e)
        foreach (int i in lstcountry.GetSelectedIndices())
            lblmessage.Text += lstcountry.Items[i].Value+",";


Protected Sub btnsubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnsubmit.Click
        For Each i As Integer In lstcountry.GetSelectedIndices()
            lblmessage.Text += lstcountry.Items(i).Value + ","
    End Sub

Build and run the project.


Is this article helpful for you?
If yes post your comment to appreciate my work and fell free to contact me. You can like me on Facebook, Google+, Linkedin and Twitter via hit on Follow us Button and also can get update follow by Email.

What do you think about this article?

If you found this article useful, please share and follow on Facebook, Twitter, Google Plus and other social media websites. To get free updates subscribe to newsletter. Please put your thoughts and feedback in comments section.