DataTable - Add New Row as First Row

Discussion in 'ASP .Net' started by Paul, Jul 11, 2008.

  1. Paul

    Paul Guest

    I have an existing datatable with 3 rows.

    I want to programatically add another row but I want to insert that new row
    in the first position/row of the datatable.

    I know who to add the new row with:
    dr = datatable.newrow
    datatable.rows.add(dr)

    My problem is that I want to insert the new row into the first position of
    the table (in front of the original three rows).

    Possible?
    Paul, Jul 11, 2008
    #1
    1. Advertising

  2. Paul

    Hermit Dave Guest

    DataTable.Rows collection which is DataRowCollection contains a method
    called InsertAt which can be used for this purpose

    http://msdn.microsoft.com/en-us/library/system.data.datarowcollection_members.aspx
    http://msdn.microsoft.com/en-us/library/system.data.datarowcollection.insertat.aspx

    HTH

    Hermit

    "Paul" <> wrote in message
    news:...
    >I have an existing datatable with 3 rows.
    >
    > I want to programatically add another row but I want to insert that new
    > row
    > in the first position/row of the datatable.
    >
    > I know who to add the new row with:
    > dr = datatable.newrow
    > datatable.rows.add(dr)
    >
    > My problem is that I want to insert the new row into the first position of
    > the table (in front of the original three rows).
    >
    > Possible?
    >
    Hermit Dave, Jul 11, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fredrik Rodin

    Sort a datatable and create a new datatable

    Fredrik Rodin, Feb 16, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    9,031
    paul.mariotti
    Sep 28, 2007
  2. Ersin Gençtürk
    Replies:
    1
    Views:
    3,466
    Ersin Gençtürk
    Oct 6, 2004
  3. Replies:
    0
    Views:
    1,839
  4. tshad

    Datatable to a new DataTable

    tshad, Apr 12, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    272
    tshad
    Apr 12, 2007
  5. sherifffruitfly
    Replies:
    0
    Views:
    109
    sherifffruitfly
    Apr 25, 2007
Loading...

Share This Page