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 is empty

Dropdownlist is empty

Scheduled Pinned Locked Moved ASP.NET
database
6 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.
  • R Offline
    R Offline
    Rajiya
    wrote on last edited by
    #1

    I have the following code but on form load my dropdownlist is empty even though there are Items present in the database.I am trying to populate the Item Ids in the dropdownlist.but it is getting populated as empty. if (!Page.IsPostBack) { //code to populate dropdown ddlItems.DataSource = objDS1; ddlItems.DataMember = objDS1.Tables["Items"].ToString(); ddlItems.DataTextField = "Name"; ddlItems.DataValueField = "Id"; ddlItems.DataBind(); } Riz

    J M I 3 Replies Last reply
    0
    • R Rajiya

      I have the following code but on form load my dropdownlist is empty even though there are Items present in the database.I am trying to populate the Item Ids in the dropdownlist.but it is getting populated as empty. if (!Page.IsPostBack) { //code to populate dropdown ddlItems.DataSource = objDS1; ddlItems.DataMember = objDS1.Tables["Items"].ToString(); ddlItems.DataTextField = "Name"; ddlItems.DataValueField = "Id"; ddlItems.DataBind(); } Riz

      J Offline
      J Offline
      J4amieC
      wrote on last edited by
      #2

      objDS1.Tables["Items"].ToString() will probably returns a string like "System.Data.DataTable, System.Data". Whereas what you want is the NAME of the table to use as datamamber. So change ddlItems.DataMember = objDS1.Tables["Items"].ToString(); to ddlItems.DataMember = "Items";

      R 1 Reply Last reply
      0
      • J J4amieC

        objDS1.Tables["Items"].ToString() will probably returns a string like "System.Data.DataTable, System.Data". Whereas what you want is the NAME of the table to use as datamamber. So change ddlItems.DataMember = objDS1.Tables["Items"].ToString(); to ddlItems.DataMember = "Items";

        R Offline
        R Offline
        Rajiya
        wrote on last edited by
        #3

        I changed it the way u've said but still the dropdownlist is empty.Is there any other way to do it? Plz let me knw. Riz

        A 1 Reply Last reply
        0
        • R Rajiya

          I have the following code but on form load my dropdownlist is empty even though there are Items present in the database.I am trying to populate the Item Ids in the dropdownlist.but it is getting populated as empty. if (!Page.IsPostBack) { //code to populate dropdown ddlItems.DataSource = objDS1; ddlItems.DataMember = objDS1.Tables["Items"].ToString(); ddlItems.DataTextField = "Name"; ddlItems.DataValueField = "Id"; ddlItems.DataBind(); } Riz

          M Offline
          M Offline
          Mike Ellison
          wrote on last edited by
          #4

          Verify that objDS1 actually contains data. I know you said the database table contains items, but perhaps there's a mistake in the code that populates objDS1? Perhaps turn tracing on, and use Page.Trace.Write to inspect your objDS1 object. Or just throw in something like Response.Write(objDS1.Tables["Items"].Rows.Count); after your code that populates objDS1 just to make sure it has rows.

          1 Reply Last reply
          0
          • R Rajiya

            I changed it the way u've said but still the dropdownlist is empty.Is there any other way to do it? Plz let me knw. Riz

            A Offline
            A Offline
            Alex Getman
            wrote on last edited by
            #5

            Maybe change to dropDownList.DataSource = yourDataSet.Tables[0].DefaultView; will helps... xedom developers team personal web page

            1 Reply Last reply
            0
            • R Rajiya

              I have the following code but on form load my dropdownlist is empty even though there are Items present in the database.I am trying to populate the Item Ids in the dropdownlist.but it is getting populated as empty. if (!Page.IsPostBack) { //code to populate dropdown ddlItems.DataSource = objDS1; ddlItems.DataMember = objDS1.Tables["Items"].ToString(); ddlItems.DataTextField = "Name"; ddlItems.DataValueField = "Id"; ddlItems.DataBind(); } Riz

              I Offline
              I Offline
              Ista
              wrote on last edited by
              #6

              change

              Rajiya wrote:

              objDS1.Tables["Items"].ToString();

              to be objDS1.Tables[Items"].TableName; that will solve it 1 line of code equals many bugs. So don't write any!!

              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