locked
GridView item move up and move down RRS feed

  • Question

  • User911209228 posted

    Hi,

    I have a asp.net application. In this application have one pop up screen and it contains one gridview and two buttons move up and move down . So I want to perform the below tasks are,

    1) Select an item  from gridview and the selected item should be highlighted as blue color.

    2) want to move up or move down the selected item When click on button move up and move down.

    Please help me to achieve this functionality.

    Thanks & Regards,

    Dileep

    Saturday, May 1, 2021 6:52 PM

All replies

  • User1535942433 posted

    Hi dileep Sanker,

    As far as I think,you firstly could save the datasource(DataTable) , in selected change event of the gridviewl, you will get the row index .

    1) Select an item  from gridview and the selected item should be highlighted as blue color.

    You could simply create an arraylist.

    ArrayList arr = new ArrayList();

    And keep on adding the ids for the selected rows after changing color to arraylist. Finally save it in Session variable.

    Session["rows"] = arr;

    Next time when another row is seleced to get the arraylist back.

    ArrayList arr = (ArrayList)Session["rows"];

    And loop and recolor the old rows with the new row and add the new row to arraylist and save it back to session.

    2) want to move up or move down the selected item When click on button move up and move down.

    You could move the row in datatable like :

    DataRow row;
    row = dtUp.row[index];
    dtUp.Rows.RemoveAt[index];
    dtUp.Rows.InsertAt[dr,index+1] //for down
    dtUp.Rows.InsertAt[dr,index-1] //for up 

    Or you could use the inherited class to add a function for moving a row up or down within a DataTable :

    http://www.codeproject.com/Tips/312545/A-method-to-move-rows-within-a-DataTable 

    After that , rebind the gridview with DataTable. You could click here for discussion about same requirement as yours.

    Best Regards,

    Yijing Sun

    Monday, May 3, 2021 5:51 AM
  • User1856118598 posted

    More Useful stuff

    Monday, May 3, 2021 12:09 PM