zoukankan      html  css  js  c++  java
  • 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();
                }
            }
        }
  • 相关阅读:
    CMD命令点滴
    Android之Service的使用
    JavaScript第一章
    Android之BroadcastReceiver的使用
    Android之短信验证
    HTML学习(一)
    新一代联合国秘书长?
    粗茶淡饭
    Access里的Case效果 解决“IErrorInfo.GetDescription 因 E_FAIL(0x80004005) 而失败!”问题!
    利用接口实现多种数据库类型的灵活更换
  • 原文地址:https://www.cnblogs.com/ggbbeyou/p/1615774.html
Copyright © 2011-2022 走看看