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. How to bind DataRow[] as a datasource with the desired display field?

How to bind DataRow[] as a datasource with the desired display field?

Scheduled Pinned Locked Moved ASP.NET
questiondatabasexmlhelptutorial
2 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.
  • C Offline
    C Offline
    Chris Richner
    wrote on last edited by
    #1

    Hi, After i execute a select against my DataTable I get a DataRow[] which I bind to a control, for instance a DropDownList. The data schema is lost, because only a DataTable holds columns, due this i have a problem to bind the data as desired: cmb.DataSource = dataRows[]; cmb.DataTextField = "[0]" // should mean row["text"], but there is no text column How do I bind the "Text" Column to a DropDownList after I executed a DataTable.Select()? Because the above code will not work. Any hints appreciated myMsg.BehindDaKeys = "Jerry Maguire";

    T 1 Reply Last reply
    0
    • C Chris Richner

      Hi, After i execute a select against my DataTable I get a DataRow[] which I bind to a control, for instance a DropDownList. The data schema is lost, because only a DataTable holds columns, due this i have a problem to bind the data as desired: cmb.DataSource = dataRows[]; cmb.DataTextField = "[0]" // should mean row["text"], but there is no text column How do I bind the "Text" Column to a DropDownList after I executed a DataTable.Select()? Because the above code will not work. Any hints appreciated myMsg.BehindDaKeys = "Jerry Maguire";

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

      That won't work because the index is a numeric and you are passing it in as a string. (The code is looking for a column named [0], not at index Zero. You can try this DataRow[] drs = dataRows[]; cmb.DataSource = drs; cmb.DataTextField = drs[0]; Otherwise you might consider doing it the programmatic way by looping through all of your rows and then DataRow[] drs = dataRows[]; foreach(DataRow dr in drs) { cmb.Items.Add(new System.Web.UI.WebControls.ListItem(MyText, dr[0].ToString())); } Torin Blair
      'In the immortal words of Socrates - "I drank what?".'

      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