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. General Programming
  3. C#
  4. refreshing second combo by first not working

refreshing second combo by first not working

Scheduled Pinned Locked Moved C#
sysadminhelp
4 Posts 3 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.
  • U Offline
    U Offline
    uglyeyes
    wrote on last edited by
    #1

    Hi, when I select region combo, I can populate country combo but when I re-select region combo again, country combo append the listitem on top of the previous value. not sure why its happening. below is my code protected void Page_Load(object sender, EventArgs e) { if (!(IsPostBack)) fillcombos(); ddRegion.SelectedIndexChanged +=new EventHandler(ddRegion_SelectedIndexChanged); } protected void ddRegion_SelectedIndexChanged(object sender, EventArgs e) { DataSet ds = new DataSet(); if (ddRegion.SelectedIndex >-1) { ds = myBLL.GetRegionOverviewAndCountryByRegionId(Convert.ToInt32(ddRegion.SelectedValue)); DataRow dr = ds.Tables[0].Rows[0]; // get the first row returned if (dr.ItemArray.Count() > 0) { txtRegionOverview.Text = dr["RegionOverview"].ToString(); ddRegion.SelectedValue = dr["RegionId"].ToString(); } if (ds.Tables[1].Rows.Count > 0) { ddCountry.DataSource = ds.Tables[1].DefaultView; ddCountry.DataTextField = "CountryName"; ddCountry.DataValueField = "CountryCode"; } else { ddCountry.DataSource = null; } ddCountry.DataBind(); } } public void fillcombos() { List<Region> regionList = new List<Region>(); regionList = myBLL.GetRegionList(); ddRegion.DataSource = regionList; ddRegion.DataTextField = "RegionName"; ddRegion.DataValueField = "RegionId"; ddRegion.DataBind(); } --- asp:DropDownList ID="ddCountry" AutoPostBack="true" runat="server" ></asp:DropDownList> in addition, I wanna it to work when i add "select a region", "select a country" at the top with ddregion.items.insert(0,"select.." please help

    realJSOPR 1 Reply Last reply
    0
    • U uglyeyes

      Hi, when I select region combo, I can populate country combo but when I re-select region combo again, country combo append the listitem on top of the previous value. not sure why its happening. below is my code protected void Page_Load(object sender, EventArgs e) { if (!(IsPostBack)) fillcombos(); ddRegion.SelectedIndexChanged +=new EventHandler(ddRegion_SelectedIndexChanged); } protected void ddRegion_SelectedIndexChanged(object sender, EventArgs e) { DataSet ds = new DataSet(); if (ddRegion.SelectedIndex >-1) { ds = myBLL.GetRegionOverviewAndCountryByRegionId(Convert.ToInt32(ddRegion.SelectedValue)); DataRow dr = ds.Tables[0].Rows[0]; // get the first row returned if (dr.ItemArray.Count() > 0) { txtRegionOverview.Text = dr["RegionOverview"].ToString(); ddRegion.SelectedValue = dr["RegionId"].ToString(); } if (ds.Tables[1].Rows.Count > 0) { ddCountry.DataSource = ds.Tables[1].DefaultView; ddCountry.DataTextField = "CountryName"; ddCountry.DataValueField = "CountryCode"; } else { ddCountry.DataSource = null; } ddCountry.DataBind(); } } public void fillcombos() { List<Region> regionList = new List<Region>(); regionList = myBLL.GetRegionList(); ddRegion.DataSource = regionList; ddRegion.DataTextField = "RegionName"; ddRegion.DataValueField = "RegionId"; ddRegion.DataBind(); } --- asp:DropDownList ID="ddCountry" AutoPostBack="true" runat="server" ></asp:DropDownList> in addition, I wanna it to work when i add "select a region", "select a country" at the top with ddregion.items.insert(0,"select.." please help

      realJSOPR Offline
      realJSOPR Offline
      realJSOP
      wrote on last edited by
      #2

      A couple of things: 0) Change your Page_Load method to do this:

      if (!IsPostBack)
      {
      fillcombos();
      ddRegion.SelectedIndexChanged +=new EventHandler(ddRegion_SelectedIndexChanged);
      }

      1. Either clear the country combo box or check IsPostBack again before adding stuff to it. 2) Your question should have been put into the ASP.Net forum. 3) Learn how to use the <PRE> tag here for code snippets.

      ".45 ACP - because shooting twice is just silly" - JSOP, 2010
      -----
      You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
      -----
      "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

      U 1 Reply Last reply
      0
      • realJSOPR realJSOP

        A couple of things: 0) Change your Page_Load method to do this:

        if (!IsPostBack)
        {
        fillcombos();
        ddRegion.SelectedIndexChanged +=new EventHandler(ddRegion_SelectedIndexChanged);
        }

        1. Either clear the country combo box or check IsPostBack again before adding stuff to it. 2) Your question should have been put into the ASP.Net forum. 3) Learn how to use the <PRE> tag here for code snippets.

        ".45 ACP - because shooting twice is just silly" - JSOP, 2010
        -----
        You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
        -----
        "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

        U Offline
        U Offline
        uglyeyes
        wrote on last edited by
        #3

        Ok I had to clear the combo in pageload but how do I add "Please select" in this situation? -- Modified Wednesday, April 13, 2011 9:02 AM

        G 1 Reply Last reply
        0
        • U uglyeyes

          Ok I had to clear the combo in pageload but how do I add "Please select" in this situation? -- Modified Wednesday, April 13, 2011 9:02 AM

          G Offline
          G Offline
          gavindon
          wrote on last edited by
          #4

          if this is in fact an asp.net application that you are just using c# for the code behind.. in the properties window look for these things

          Items (collection) set the first item in that collection to "Please Select" or whatever you wish

          AppendDataBoundItems set to true

          ViewStateMode = false

          Go to the first box and set to AutoPostBack = true.

          Programming is a race between programmers trying to build bigger and better idiot proof programs, and the universe trying to build bigger and better idiots, so far... the universe is winning.

          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