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. HELP!! DropDownList not displaying first record

HELP!! DropDownList not displaying first record

Scheduled Pinned Locked Moved ASP.NET
help
5 Posts 4 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
    User 3400231
    wrote on last edited by
    #1

    I was about to publish my site live until I discovered that a DDL is not displaying the first record from the results set! My code is as follows: if (objRdr.Read()) { ddlModelTypes.DataSource = objRdr; ddlModelTypes.DataValueField = "TypeId"; ddlModelTypes.DataTextField = "ModelType"; ddlModelTypes.DataBind(); } I thought the following line was replacing the first value: ddlModelTypes.Items.Insert(0, "Other"); However, I took this out and it's still not displaying the first record value so any help will be much appreciated. Thanks Lorna

    T N 2 Replies Last reply
    0
    • U User 3400231

      I was about to publish my site live until I discovered that a DDL is not displaying the first record from the results set! My code is as follows: if (objRdr.Read()) { ddlModelTypes.DataSource = objRdr; ddlModelTypes.DataValueField = "TypeId"; ddlModelTypes.DataTextField = "ModelType"; ddlModelTypes.DataBind(); } I thought the following line was replacing the first value: ddlModelTypes.Items.Insert(0, "Other"); However, I took this out and it's still not displaying the first record value so any help will be much appreciated. Thanks Lorna

      T Offline
      T Offline
      ToddHileHoffer
      wrote on last edited by
      #2

      You do not need to call objRdr.Read(). Try the following. connection.open ddlModelTypes.DataSource = objRdr; ddlModelTypes.DataValueField = "TypeId"; ddlModelTypes.DataTextField = "ModelType"; ddlModelTypes.DataBind(); connection.dispose();

      I didn't get any requirements for the signature

      U 1 Reply Last reply
      0
      • U User 3400231

        I was about to publish my site live until I discovered that a DDL is not displaying the first record from the results set! My code is as follows: if (objRdr.Read()) { ddlModelTypes.DataSource = objRdr; ddlModelTypes.DataValueField = "TypeId"; ddlModelTypes.DataTextField = "ModelType"; ddlModelTypes.DataBind(); } I thought the following line was replacing the first value: ddlModelTypes.Items.Insert(0, "Other"); However, I took this out and it's still not displaying the first record value so any help will be much appreciated. Thanks Lorna

        N Offline
        N Offline
        Nishant Singh
        wrote on last edited by
        #3

        Do Like this

        Member 3402886 wrote:

        ddlModelTypes.DataSource = objRdr; ddlModelTypes.DataValueField = "TypeId"; ddlModelTypes.DataTextField = "ModelType"; ddlModelTypes.DataBind();

        No need to Call

        Member 3402886 wrote:

        if (objRdr.Read())

        No need to Call , otherwise everything else looks ok , it should work

        1 Reply Last reply
        0
        • T ToddHileHoffer

          You do not need to call objRdr.Read(). Try the following. connection.open ddlModelTypes.DataSource = objRdr; ddlModelTypes.DataValueField = "TypeId"; ddlModelTypes.DataTextField = "ModelType"; ddlModelTypes.DataBind(); connection.dispose();

          I didn't get any requirements for the signature

          U Offline
          U Offline
          User 3400231
          wrote on last edited by
          #4

          Thanks but I'm using the if (objRdr.Read()) to check that records have been returned as sometimes there will be no records - is there another way to check this before using DataBind?

          P 1 Reply Last reply
          0
          • U User 3400231

            Thanks but I'm using the if (objRdr.Read()) to check that records have been returned as sometimes there will be no records - is there another way to check this before using DataBind?

            P Offline
            P Offline
            Paddy Boyd
            wrote on last edited by
            #5

            It doesn't matter if there's no records, the binding won't fail. You can always check post binding (i.e. count the items in the list) if you need to do something in that case. Calling dr.Read moves the reader onto the second record...

            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