Solved

Populate textbox from dropdown control selection asp.net visual studio 2008

Posted on 2008-06-17
1
492 Views
Last Modified: 2013-11-26
I have a dropdown control with a number of options in asp.net page

If I select an option from the dropdown list I want to the selected text of the dropdown to be appended to a multi line textbox on the same form.

If I select another option from the dropdown control I want that selected text to also be appended to the textbox.  So the end result would be a multi line text box populated with say upto 6 lines.

I need a quick over view demo not a link to another site

Thanks

0
Comment
Question by:mugsey
1 Comment
 
LVL 53

Accepted Solution

by:
Dhaest earned 500 total points
ID: 21800689
A very easy example
ASPX-file
---------
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:DropDownList ID="DropDownList1" runat="server" 
        onselectedindexchanged="DropDownList1_SelectedIndexChanged" 
        AutoPostBack="True">
        <asp:ListItem>Item1</asp:ListItem>
        <asp:ListItem>Item2</asp:ListItem>
        <asp:ListItem Value="Item3"></asp:ListItem>
        <asp:ListItem>Item4</asp:ListItem>
        <asp:ListItem>Item5</asp:ListItem>
        <asp:ListItem>Item6</asp:ListItem>
        <asp:ListItem>Item7</asp:ListItem>
    </asp:DropDownList>
    <p>
    <asp:TextBox ID="TextBox1" runat="server" Height="141px" Rows="6" 
            TextMode="MultiLine"></asp:TextBox>
    </p>
    </form>
</body>
</html>
 
 
ASPX.CS-file
------------
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
 
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
 
 
 
        if (!Page.IsPostBack)
        {
        }
 
    }
 
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        TextBox1.Text += DropDownList1.SelectedValue + System.Environment.NewLine;
    }
    
 
}

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question