posted on Sunday, July 18, 2004 10:06 PM by warstar

Moving a Row up in a Datatable

Hey all,

I was bizzy with a little project and it needed to move row's up and down in a Datarow.
Problem was i couldn't move the datarows so i needed to move the info.
The way i moved a row up was like this (this happend in ItemCommand with a command named Up):

object[] up = DataTableFields.Rows[e.Item.ItemIndex].ItemArray;
object[] down = DataTableFields.Rows[e.Item.ItemIndex-1].ItemArray;
DataTableFields.Rows[e.Item.ItemIndex].ItemArray = down;
DataTableFields.Rows[e.Item.ItemIndex-1].ItemArray = up;

Don't really like this way but hey it works.

Happy netting,
warnar

Comments