Dropdownlist populates Text Box in ASP.net

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" "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">
    <div>
    
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 
            DataSourceID="SqlDataSource1" DataTextField="name" DataValueField="name" 
            Height="26px" Width="127px">
        </asp:DropDownList>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ordersConnectionString %>" 
            SelectCommand="SELECT [name], [territory] FROM [names]"></asp:SqlDataSource>
    
    </div>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </form>
</body>
</html>

Open in new window

jseaman12Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
varungdCommented:
One more thing is in this HTML code u should set the 'DataValueField=TERRITORY' .
 
 
 
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.