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

Pass ListBox Multiple Values To TextBox 


ListBox  Does Not Enter The Values  in  Run Time.


TextBox Enter The Values in Run Time

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


HTML Coding

<html xmlns="">
<head id="Head1" runat="server">
    <form id="form1" runat="server">

        <asp:ListBox ID="ListBox1" runat="server" Height="126px" Width="207px">

        <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 />

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


Next - Click the Button  Pass ListBox Values To TextBox


Post a Comment