Dropdownlist populates Text Box in

Posted on 2008-11-05
Last Modified: 2012-05-05
I have a query that populates a drop down list. It has two fields NAME | TERRITORY

Textbox is blank. When end user selects the drop down list then the TERRITORY is populated in the textbox.

How can I do this in ASP.NET

Here is my code

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">

<head runat="server">

    <title>Untitled Page</title>



    <form id="form1" runat="server">



        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 

            DataSourceID="SqlDataSource1" DataTextField="name" DataValueField="name" 

            Height="26px" Width="127px">


        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 

            ConnectionString="<%$ ConnectionStrings:ordersConnectionString %>" 

            SelectCommand="SELECT [name], [territory] FROM [names]"></asp:SqlDataSource>



    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>




Open in new window

Question by:jseaman12
    LVL 5

    Accepted Solution

    Set the  'TERRITORY' as the valuefield of  that dropdownlist and use below given code
      <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 
                DataSourceID="SqlDataSource1" DataTextField="name" DataValueField="name" 
                Height="26px" Width="127px" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
     protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
             TextBox1.Text=  DropDownList1.SelectedValue;

    Open in new window

    LVL 5

    Expert Comment

    One more thing is in this HTML code u should set the 'DataValueField=TERRITORY' .

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    I have developed many web applications with asp & and to add and use a dropdownlist was always a very simple task, but with the new, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
    In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    754 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

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now