POPULATE TEXT BOXES ON DROPDOWNLIST SELECT IN ASP.NET

Andrew Watson

Total Post:39

Points:273
Posted by  Andrew Watson
C#  Dropdown 
 858  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. Chris S

    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>

  1. Allen Scott

    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

    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!