Populate text boxes on dropdownlist select in asp.net

Total Post:39

Points:273
C#  Dropdown 
 1182  View(s)
Ratings:
Rate this:

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>
    <asp:ListItem>Annoucement</asp:ListItem>
</asp:DropDownList>

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.

  1. Post:48

    Points:336
    Re: Populate text boxes on dropdownlist select in asp.net

    Clients ide coding using JavaScript

    .aspx

      <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>
            <asp:ListItem>Annoucement</asp:ListItem>
        </asp:DropDownList>

    .cs 

      protected void Page_Load(object sender, EventArgs e)
            {
     
                dropDownType.Attributes.Add("onChange","return OnSelectedIndexChange();");
            }
    JavaScript:
     
       <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";
              }</script>

      Modified On Apr-07-2018 03:38:04 AM
  1. Post:46

    Points:324
    Re: Populate text boxes on dropdownlist select in asp.net

    Simply you can do this in DropDown SelectedIndexChanged Event 

    SelectedIndexChanged

    Edit

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

    Code Behind:

    C#:

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

      Modified On Apr-07-2018 03:39:11 AM

Answer