Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Dropdownlist control problem

Dropdownlist control problem

Scheduled Pinned Locked Moved ASP.NET
help
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cheguri
    wrote on last edited by
    #1

    Dear Friends, I have three dropdownlist controls. When the page loads, first dropdownlist is filled and the remaining two are empty. When I select some value in First dropdownlist then corresponding values to be populated in Second dropdownlist and same When I select some value in Second dropdownlist then corresponding values to be populated in Third dropdownlist. The problem is, Whatever I select in the First dropdownlist automatically the first item only getting selected. Even If I selected the 5th Item, then also the First Item only getting selected. Please solve my problem. Thanks & Regards, Dileep.

    D A S 3 Replies Last reply
    0
    • C cheguri

      Dear Friends, I have three dropdownlist controls. When the page loads, first dropdownlist is filled and the remaining two are empty. When I select some value in First dropdownlist then corresponding values to be populated in Second dropdownlist and same When I select some value in Second dropdownlist then corresponding values to be populated in Third dropdownlist. The problem is, Whatever I select in the First dropdownlist automatically the first item only getting selected. Even If I selected the 5th Item, then also the First Item only getting selected. Please solve my problem. Thanks & Regards, Dileep.

      D Offline
      D Offline
      daveyerwin
      wrote on last edited by
      #2

      Here is a simple example concerning updating derop down list based on selction in another drop down ...

      <%@ Page Language="C#" %>
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
      Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
      <script runat="server">
      protected void Button1_Click(object sender, EventArgs e)
      {

                   DropDownList1.Items.Clear();
          String\[\] ds = {"hi RED","sup RED"};
          String\[\] ds1 = { "hi BLUE", "sup BLUE" };
          if (DropDownList2.SelectedValue == "RED")
          {
              DropDownList1.DataSource = ds;
              DropDownList1.DataBind();
           }
         if (DropDownList2.SelectedValue == "BLUE")
          {
              DropDownList1.DataSource = ds1;
              DropDownList1.DataBind();
          }
       }
          </script>
      

      <html xmlns="http://www.w3.org/1999/xhtml" >
      <head id="Head1" runat="server">
      <title>Untitled Page</title>
      <style type="text/css">
      #UpdatePanel1 { width:300px; height:100px; } </style>
      </head>
      <body>
      <form id="form1" runat="server">
      <div style="padding-top: 10px">
      <asp:ScriptManager ID="ScriptManager1" runat="server">
      </asp:ScriptManager>
      <asp:UpdatePanel ID="UpdatePanel1" runat="server">
      <ContentTemplate>
      <fieldset>
      <legend>UpdatePanel</legend>
      <asp:DropDownList ID="DropDownList1" runat="server">
      </asp:DropDownList>
      <asp:DropDownList ID="DropDownList2" runat="server">
      asp:ListItemRED</asp:ListItem>
      asp:ListItemBLUE</asp:ListItem>
      </asp:DropDownList>
      <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
      </fieldset>
      </ContentTemplate>
      </asp:UpdatePanel>
      <br />
      </div>
      </div>
      </form>
      </body>
      </html>

      1 Reply Last reply
      0
      • C cheguri

        Dear Friends, I have three dropdownlist controls. When the page loads, first dropdownlist is filled and the remaining two are empty. When I select some value in First dropdownlist then corresponding values to be populated in Second dropdownlist and same When I select some value in Second dropdownlist then corresponding values to be populated in Third dropdownlist. The problem is, Whatever I select in the First dropdownlist automatically the first item only getting selected. Even If I selected the 5th Item, then also the First Item only getting selected. Please solve my problem. Thanks & Regards, Dileep.

        A Offline
        A Offline
        Ankur m
        wrote on last edited by
        #3

        Your description doesn't tell me much about the cause of your problem. Could you post some code, so that we may be able to help you.

        ..Go Green..

        1 Reply Last reply
        0
        • C cheguri

          Dear Friends, I have three dropdownlist controls. When the page loads, first dropdownlist is filled and the remaining two are empty. When I select some value in First dropdownlist then corresponding values to be populated in Second dropdownlist and same When I select some value in Second dropdownlist then corresponding values to be populated in Third dropdownlist. The problem is, Whatever I select in the First dropdownlist automatically the first item only getting selected. Even If I selected the 5th Item, then also the First Item only getting selected. Please solve my problem. Thanks & Regards, Dileep.

          S Offline
          S Offline
          Sandesh M Patil
          wrote on last edited by
          #4

          Are you binding the dropdown in page_load event. If so is it within if(!Ispostback) ? I think thats the problem you did not bind the dropdown within if(!Ispostback) I think this may help u............. :)

          P 1 Reply Last reply
          0
          • S Sandesh M Patil

            Are you binding the dropdown in page_load event. If so is it within if(!Ispostback) ? I think thats the problem you did not bind the dropdown within if(!Ispostback) I think this may help u............. :)

            P Offline
            P Offline
            PunkIsNotDead
            wrote on last edited by
            #5

            Your problem could it be like sandympatil said! or maybe you're setting the same dropDownList1.DataValueField in the data source... for example I have as source: -column1----column2 --------------------- -red------------value1 -blue-----------value1 -orange-------value1 -black----------value1 and dropdownlist is dropDownList1.DataTextField = "column1"; dropDownList1.DataValueField = "column2"; look out that. If that's so, the post back always select the first option with 'value1'... Ahh! I recommend you to use ajax CascaddingDropDownList Here!![^]

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups