Home > DeveloperSection > Forums > Populate text boxes on dropdownlist select in asp.net
Andrew Watson
Andrew Watson

Total Post:39

Points:273
Posted on    December-08-2014 2:09 AM

 ASP.Net C#  Dropdown 
Ratings:


 2 Reply(s)
 497  View(s)
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.



Chris S
Chris S

Total Post:48

Points:336
Posted on    December-08-2014 6:19 AM

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>

Allen Scott

Total Post:36

Points:254
Posted on    December-08-2014 7:34 AM

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

}


Don't want to miss updates? Please click the below button!

Follow MindStick