Showing posts with label ListBox. Show all posts
Showing posts with label ListBox. Show all posts

How To Pass Multiple ListBox Values To TextBox Using Asp.Net C#

Pass ListBox Multiple Values To TextBox 

ListBox


ListBox  Does Not Enter The Values  in  Run Time.


TextBox


TextBox Enter The Values in Run Time


ListBox Multiple Values Pass To TextBox  Same as the ListBox Formate Using Asp.Net C#.




DEMO






HTML Coding


<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
       

        <asp:ListBox ID="ListBox1" runat="server" Height="126px" Width="207px">
            <asp:ListItem>1</asp:ListItem>
            <asp:ListItem>2</asp:ListItem>
            <asp:ListItem>3</asp:ListItem>
        </asp:ListBox>


        <asp:TextBox ID="TextBox1" runat="server" Height="117px" TextMode="MultiLine" Width="209px"></asp:TextBox>
       

        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Pass  Values ListBox to TextBox" />
        <br />
        <br />
   
         
    </div>
    </form>
</body>
</html>




C# Coding


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ListBoxToTextBox : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {

        for (int i = 0; i < ListBox1.Items.Count; i++)
        {

            TextBox1.Text += ListBox1.Items[i] + "\r";


        }

    }

}




First -  Add - New - WebForm 









Next - Add the ListBox From ToolBox








Next - Add the TextBox From ToolBox








Next - Add  the Button - Change The Required Name









Next - Right Click  the ListBox - Add List Item - Change The Text Name









Added The List Item Values to the ListBox










Next - Change TextMode From TextBox  MultiLine

Next - Double- Click - Write Coding to Button









Next - Write Coding To Pass Values From ListBox To TextBox (For Loop)










Next - Run (F5) the WebForm - Display the List Item in ListBox






OUTPUT



Next - Click the Button  Pass ListBox Values To TextBox






How To Remove Duplicate Values From ListBox Without Using DataBase in Asp.net C#



          Remove Duplicate Values  From ListBox 


Remove  Duplicate Values two ListBoxes  Using Without  Database Connection in Asp.net C#

Foreach  & if Conditions  Using  Remove Duplicate Values.





DEMO





Html Coding



<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body style="height243px">
    <form id="form1" runat="server">
    <div>
   
    <asp:ListBox ID="ListBox1" runat="server" Height="104px"
 OnSelectedIndexChanged="ListBox1_SelectedIndexChanged" Width="95px">

            <asp:ListItem>AAA</asp:ListItem>
            <asp:ListItem>BBB</asp:ListItem>
            <asp:ListItem>CCC</asp:ListItem>
            <asp:ListItem>DDD</asp:ListItem>

        </asp:ListBox>


  <asp:ListBox ID="ListBox2" runat="server" Height="142px" Width="110px" >

            <asp:ListItem>AAA</asp:ListItem>
            <asp:ListItem>BBB</asp:ListItem>
            <asp:ListItem>CCC</asp:ListItem>
            <asp:ListItem>DDD</asp:ListItem>
            <asp:ListItem>EEE</asp:ListItem>
            <asp:ListItem>FFF</asp:ListItem>
            <asp:ListItem>GGG</asp:ListItem>
            <asp:ListItem>EEE</asp:ListItem>

        </asp:ListBox>   

     
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
 Text="Remove Duplicates" />
   
    </div>
    </form>
</body>


</html>


C# Coding



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {



        foreach (ListItem LISTBOXES in ListBox1.Items)
        {

            if (ListBox2.Items.Contains(LISTBOXES) == true)
            {

                ListBox2.Items.Remove(LISTBOXES);

            }

        }



    }



}




First  Add - New - Webform 








Next - Add the  Two ListBoxes From Toolbox







Select - ListBox1 - Right Click - Select Edit Items 









Next - Add  ListItems (Required)









Next - Add - Text Name (Reqiured) - OK








Next - Select Listbox2 - Right Click - Select Edit Items - Add - ListItems -  Enter the Text Name(Required) - OK.








Show The ListBoxes  Text Values 










Next - Add the Button - Change Text  Name - Double Click Button







Write The Coding Using Foreach  & Remove Duplicate  Values From ListBox2







        


Next - Run (F5) - Show the List Box Vaues 









Next -  Click The Button  - Duplicate Values  Remove & Show Below