1) if dgoutimage. datasource = set (recfileargs)
(Move up)
Dgoutimage. datasource = new bindinglist <recfileargs> (recfileargs1 );
// If multiple rows are selected
If (dgoutimage. selectedrows. Count> 1)
{
Return;
}
Dgoutimage. Focus ();
// The currently selected row number
Int rowindex = dgoutimage. currentrow. index;
If (rowindex! = 0)
{
Recfileargs _ recccurr = dvrplaylistright [rowindex];
Recfileargs _ reccper = dvrplaylistright [rowindex-1];
Dvrplaylistright [rowindex] = _ reccper;
Dvrplaylistright [rowindex-1] = _ recccurr;
Dgoutimage. datasource = dvrplaylistright;
Dgoutimage. Refresh ();
Dgoutimage. Rows [rowindex-1]. Selected = true;
Dgoutimage. currentcell = dgoutimage. Rows [rowindex-1]. cells [0];
}
If (rowindex-1 = 0)
{
Up button. Enabled = false;
}
Else
{
Up button. Enabled = true;
}
2) If dgoutimage. datasource = datatable
(Move down)
Object [] _ rowdata = datatable. Rows [I]. itemarray;
Datatable. Rows [I]. itemarray = datatable. Rows [I + 1]. itemarray
Datatable. Rows [I + 1]. itemarray = _ rowdata;
========================================================== ========
Set sortorder int in the database table.
-
SQL code
-
insert Tb (title, sortorder) Select @ title, (select isnull (max (sortorder), 0) + 1 from TB) as sortorder create procedure tb_move (@ ID int, @ upordown nchar (4) as declare @ currentorder int, @ exorder int select @ currentorder = sortorder from TB where id = @ ID if @ upordown = 'up' select top 1 @ exorder = sortorder from TB where sortorder <@ currentorder order by sortorder DESC if @ upordown = 'low' select top 1 @ exorder = sortorder from TB where sortorder> @ currentorder order by sortorder ASC if @ exorder is null return else begin update TB set sortorder = 0 where sortorder = @ currentorder update TB set sortorder = @ currentorder where sortorder = @ exorder update TB set sortorder = @ exorder where sortorder = 0 end go
-
-
C # code
-
Public void upordown (int id, string upordown) {try {sqlparameter [] sqlparams = new sqlparameter [] {New sqlparameter ("@ ID", ID ), new sqlparameter ("@ upordown", upordown)}; dbhelper. executenonquery ("tb_move", sqlparams);} catch {}} protected void gridview_romcommand (Object sender, gridviewroweventargs e) {swith (E. commandname) {Case "up": // note that you must add the commandname = "up" attribute to the button to move up, And commandargument = '<% # eval ("ID ") %> 'upordown (Int. parse (E. commandargument. tostring (), "up"); bindgridview (); break; Case "down": // note that you must add the commandname = "down" attribute to the button to be moved up at the front end, and commandargument = '<% # eval ("ID") %>' upordown (Int. parse (E. commandargument. tostring (), "down"); bindgridview (); break ;}} private void bindgridview () {dataset DS = dbhelper. excutenoquery ("select * from TB order by sortorder ASC"); // obtain by sequence ASC. and bound ,}