You can actually use a stored procedure to add a sequence (SORT) field to the table.
Create procedure [dbo]. [sp_MoveUp_contactinfo] -- move up. Move down similar to this.
(
@ Pkey bigint
)
AS
BEGIN
Declare @ sequence as int
Select @ sequence = sequence from tb_contact_info where primary key = @ pkey
Declare @ Dpkey as bigint
Select @ Dpkey = primary key from table name where sequence = (select max (sequence) from table name where sequence & lt; @ sequence)
If exists (select top 1 sequence from table name where sequence & lt; @ sequence)
Begin
Update tb_contact_info set sequence = (select top 1 sequence from tb_contact_info as a where a. Primary Key = @ Dpkey) where primary key = @ pkey;
Update table name set sequence = sequence + 1 where primary key = @ Dpkey;
End
END
Add two template columns in the GridView. Put two buttons in it. Write the following code in the RowCommand event.
C # codestring type = ""; ImageButton btn = e. commandSource as ImageButton; if (btn. ID = "moveDown") {type = "up";} if (btn. ID = "moveUp") {type = "down";} GridViewRow row = btn. namingContainer as GridViewRow; string pkey = dgv_Membership.DataKeys [row. rowIndex]. value. toString (); string contenttype = row. cells [5]. text. replace ("& nbsp ;",""). trim (); // The method for executing the stored procedure is called here if (errMsg! = "") {Response. Write (clsCommon. Msg ("Errors:" + errMsg);} // bind it again here.
Write in RowDataBound event
C # code protected void grvNews_RowDataBound (object sender, GridViewRowEventArgs e) {if (e. row. rowType = DataControlRowType. dataRow) {if (e. row. rowIndex = 0) {e. row. findControl ("moveUp "). visible = false;} if (e. row. dataItemIndex = (dgv_Membership.DataSource as DataView ). count-1) {e. row. findControl ("moveDown "). visible = false ;}}}