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. problem with dropdownlist

problem with dropdownlist

Scheduled Pinned Locked Moved C#
databasehelp
4 Posts 2 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.
  • P Offline
    P Offline
    Prashant Gadhave
    wrote on last edited by
    #1

    In the project I am working on ,I need to add new records in a database and show the first column of all these existing records in a dropdownlist on the same page.The problem is that when I add a new record its value doesn't get reflected in the dropdownlist and I need to refresh the page to see the changes.What should I do so that I will not need to refresh the page and still the value will get added to dropdownlist. Thank you.

    R 1 Reply Last reply
    0
    • P Prashant Gadhave

      In the project I am working on ,I need to add new records in a database and show the first column of all these existing records in a dropdownlist on the same page.The problem is that when I add a new record its value doesn't get reflected in the dropdownlist and I need to refresh the page to see the changes.What should I do so that I will not need to refresh the page and still the value will get added to dropdownlist. Thank you.

      R Offline
      R Offline
      ricardojb
      wrote on last edited by
      #2

      if you dropdownlist is called for example dropDownList1. dropDownList1.DataBind();

      P 1 Reply Last reply
      0
      • R ricardojb

        if you dropdownlist is called for example dropDownList1. dropDownList1.DataBind();

        P Offline
        P Offline
        Prashant Gadhave
        wrote on last edited by
        #3

        I have already done it ,my code on page load is query = "select * from CashDataTable"; conn = new OleDbConnection("FILE NAME=C:\\abc.udl"); conn.Open(); cmd = new OleDbCommand(query,conn); reader = cmd.ExecuteReader(); DropDownList1.DataSource = reader; DropDownList1.DataTextField = "AcctNumber"; DropDownList1.DataValueField = "AcctNumber"; DropDownList1.DataBind(); conn.Close(); but still it doesn't work.

        R 1 Reply Last reply
        0
        • P Prashant Gadhave

          I have already done it ,my code on page load is query = "select * from CashDataTable"; conn = new OleDbConnection("FILE NAME=C:\\abc.udl"); conn.Open(); cmd = new OleDbCommand(query,conn); reader = cmd.ExecuteReader(); DropDownList1.DataSource = reader; DropDownList1.DataTextField = "AcctNumber"; DropDownList1.DataValueField = "AcctNumber"; DropDownList1.DataBind(); conn.Close(); but still it doesn't work.

          R Offline
          R Offline
          ricardojb
          wrote on last edited by
          #4

          you are doing that on Page_Load, that only runs when the page loads, that's why it updates when you refresh the page, if you want to force it to update you need to call DataBind again. I don't know how you are updating the database, You might need to set the autopostback of controls that update the database to true. In that case you won't need a separate call to the DataBind method because it's executed at the database level, however, it also depends on what you are doing the the dropdownlist, if you want to keep the selection the user makes you need to check the IsPostBack property and not bind the control every time the page loads,again, not knowing more is difficult to say how to do it.

          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