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. Insert empty datarow into datatable

Insert empty datarow into datatable

Scheduled Pinned Locked Moved ASP.NET
tutorialquestion
2 Posts 1 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
    cocoonwls
    wrote on last edited by
    #1

    Hi all, I am knowing how to insert datarow into datatable by using method below:

    DataTable dt = new DataTable();
    DataRow myNewRow;
    myNewRow = dt.NewRow();
    myNewRow[0] = 1;
    myNewRow[1] = "johndoe" ;
    dt.Rows.Add(myNewRow);

    But in my case, i have upto 20 columns for a row data.Then i don't want to use the For...Loop to declare each column's value. So, may i know its there have any others alternative to insert a empty row into datatable? Note: Actually at the end, i will bound this datatable to a dropdwonlist. any helps are welcome Thanks in advance regards cocoonwls

    C 1 Reply Last reply
    0
    • C cocoonwls

      Hi all, I am knowing how to insert datarow into datatable by using method below:

      DataTable dt = new DataTable();
      DataRow myNewRow;
      myNewRow = dt.NewRow();
      myNewRow[0] = 1;
      myNewRow[1] = "johndoe" ;
      dt.Rows.Add(myNewRow);

      But in my case, i have upto 20 columns for a row data.Then i don't want to use the For...Loop to declare each column's value. So, may i know its there have any others alternative to insert a empty row into datatable? Note: Actually at the end, i will bound this datatable to a dropdwonlist. any helps are welcome Thanks in advance regards cocoonwls

      C Offline
      C Offline
      cocoonwls
      wrote on last edited by
      #2

      Hi all, I got a solution base on my case(in my case i want bind this dt to dropdownlist). In the dropdownlist control, firstly set appenddatabounditems to true, then add a empty items into collection. Then, at .cs just bind the data into that dropdownlist. Off course you have set the datatextfeild and datavaluefeild. :laugh: thanks for those view my question~ regards lswang

      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