Friday, 31 October 2014

Moving row of a DataTable up and down in asp.net



move up down rows in datatable



Description:-



In this example we explain that how to move rows up and down in datatable in asp.net. or Moving row of a DataTable up and down. Or interchange the position of DataRow in DataTable or change the index or position of the datarow in datatable in asp.net.

Sometime You will need to add an Order column, and assign the DataGrid with a DataView sorted by the Order column. In order to switch the position of rows, you will need to set the Order value of each row.

That was the real problem that I was faced before sometime and then now I wil solved it.my problem was that I want to arrane thje datarow in datatable. In my datatable's one coloumn is that "colorarea". And if colorarea's value in datarow is "cell" then its position remain same in datatable but colorarea's value is "row" then it's datarow position are moved to the last position of the Datatable rows.

So how to handle that's type of situation and so far we will demonstrate to move or change the position of the datarow in datatable in asp.net using c#.

 Dynamically Bind Data in Ajax Accordion Panel Bind Data to Accordion from databse


Restrict the size of File when Uploaded How to Restrict the size of File when uploaded by user


Code:-


DataTable table = new DataTable();
        for (int i = 0; i < table.Rows.Count; i++)
        {
            if (table.Rows[i].ToString().Equals("rows"))
            {
                DataRow selectedRow = table.Rows[i];
                DataRow newRow = table.NewRow();
                newRow.ItemArray = selectedRow.ItemArray; // copy data
                table.Rows.Remove(selectedRow);
                table.Rows.InsertAt(newRow, i + 1 / -1);
            }
        }

0 comments:

Post a Comment