Populate text boxes on dropdownlist select in asp.net

I am new at asp.net. I have a dropdownlist which is populated in code behind. When I select any item from dropdownlist, it should populate two textbox and another dropdownlist according to data from table.


<asp:DropDownList runat="server" ID="dropDownExisting"></DropDownList><br />
<asp:TextBox ID="txtPromotion" runat="server" Width="77px" ></asp:TextBox><br />
<asp:TextBox ID="txtSubject" runat="server" Width="288px"></asp:TextBox><br />
<asp:DropDownList ID="dropDownType" runat="server">
    <asp:ListItem>Monthly Newsleter</asp:ListItem>
    <asp:ListItem>Webbinar Newsleter</asp:ListItem>

I want it to be done on client side. Where do I have to provide database connectivity? Do I require to use ajax control like update panel? Or javascript will work well? I want it on client side.

Last updated:12/8/2014 7:34:31 AM

2 Answers

Anonymous User
Anonymous User

Clients ide coding using JavaScript


  <asp:DropDownList runat='server' ID='dropDownExisting' ></asp:DropDownList><br
    <asp:TextBox ID='txtPromotion' runat='server' Width='77px'></asp:TextBox><br />
    <asp:TextBox ID='txtSubject' runat='server' Width='288px'></asp:TextBox><br />
    <asp:DropDownList ID='dropDownType'runat='server'>
        <asp:ListItem>Monthly Newsleter</asp:ListItem>
        <asp:ListItem>Webbinar Newsleter</asp:ListItem>


  protected void Page_Load(object sender, EventArgs e)
            dropDownType.Attributes.Add('onChange','return OnSelectedIndexChange();');
   <script type='text/javascript'>
          function OnSelectedIndexChange() {
              var sel= document.getElementById('dropDownExisting');
              var text= sel.options.value;
              var out= document.getElementById('txtPromotion');
              out.value += text + '\n';

Allen Scott
Allen Scott

Simply you can do this in DropDown SelectedIndexChanged Event 



<asp:UpdatePanel ID='upDdlGoal' runat='server' UpdateMode='always'>
      <asp:DropDownList ID='drop1' runat='server' AutoPostBack='true' EnableViewState='true' OnSelectedIndexChanged='drop1_SelectedIndexChanged'>                   
        <asp:AsyncPostbackTrigger ControlID='drop1' EventName='SelectedIndexChanged' /> 

Code Behind:


protected void drop1_SelectedIndexChanged(object sender, System.EventArgs e)
    //Connectivity coding