GRIDVIEW中实现上移下移的存储过程

建一个表  t_hoteladvertise

有如下字段:
ID  自动增长(主要)
SortID  INT (主要)
Title  NVARCHAR(50)

 

CREATE proc sp_ehotel_DownAdvertise

@ID INT
as
DECLARE @SortID int
DECLARE @TempSortID INT
DECLARE @TempID INT

BEGIN  TRAN

SELECT @SortID=SortID  from t_hoteladvertise where [ID]=@ID

SELECT @TempSortID=max(SortID) from t_hoteladvertise where SortID>@SortID
SELECT @TempID=[ID] from t_hoteladvertise WHERE SortID=@TempSortID

if @@error>0 or @@rowcount<>1
goto NeedRollBack

UPDATE t_hoteladvertise SET SortID=@SortID WHERE [ID]=@TempID

if @@error>0 or @@rowcount<>1
goto NeedRollBack

UPDATE t_hoteladvertise SET SortID=@TempSortID where [ID]=@ID

 NeedRollBack:
if @@error>0 or @@rowcount<>1
  rollback tran
else
commit tran
GO


CREATE proc sp_ehotel_UpAdvertise
@ID INT
as
DECLARE @SortID int
DECLARE @TempSortID INT
DECLARE @TempID INT

BEGIN  TRAN

SELECT @SortID=SortID  from t_hoteladvertise where [ID]=@ID

SELECT @TempSortID=max(SortID) from t_hoteladvertise where SortID<@SortID
SELECT @TempID=[ID] from t_hoteladvertise WHERE SortID=@TempSortID

if @@error>0 or @@rowcount<>1
goto NeedRollBack

UPDATE t_hoteladvertise SET SortID=@SortID WHERE [ID]=@TempID

if @@error>0 or @@rowcount<>1
goto NeedRollBack

UPDATE t_hoteladvertise SET SortID=@TempSortID where [ID]=@ID

 NeedRollBack:
if @@error>0 or @@rowcount<>1
  rollback tran
else
commit tran
GO


代码段:
 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        SqlConnection conn = new SqlConnection();

       if (e.CommandName == "down")
        {
            int IndexID = Convert.ToInt32(e.CommandArgument);
            try
            {
                XMLData.OpenDatabase(conn);
                XMLData.ExecuteNonQuery(conn, "SP_EHOTEL_UPADVERTISE", IndexID);
                Label2.Visible = true;
                Label2.Text = "下移成功!";
            }
            catch (Exception)
            {
                Response.Write("<script language='javascript'>alert('下移出错,点取消返回');</" + "script>");
            }
            finally
            {
                XMLData.CloseDatabase(conn);
                BindAdvertise();
            }
        }
        if (e.CommandName == "up")
        {
            int IndexID = Convert.ToInt32(e.CommandArgument);
            try
            {
                XMLData.OpenDatabase(conn);
                XMLData.ExecuteNonQuery(conn, "SP_EHOTEL_DOWNADVERTISE", IndexID);
                Label2.Visible = true;
                Label2.Text = "上移成功!";
            }
            catch (Exception)
            {
                Response.Write("<script language='javascript'>alert('上移出错,点取消返回');</" + "script>");
            }
            finally
            {
                XMLData.CloseDatabase(conn);
                BindAdvertise();
            }
        }
    }

转载于:https://www.cnblogs.com/zhangchenliang/archive/2007/04/23/724352.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值