Tuesday 2 December 2014

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

No comments    
categories: , , ,
Pass ListBox Multiple Values To TextBox 

ListBox


ListBox  Does Not Enter The Values  in  Run Time.


TextBox


TextBox Enter The Values in Run Time


                          DEMO






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










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";


        }

    }

}

  































0 comments:

Post a Comment