zoukankan      html  css  js  c++  java
  • GridView事件中获取rowIndex值

    其实可以用存储过程来实现.在表中加一个sequence(排序)字段.
    CREATE PROCEDURE [dbo].[sp_MoveUp_contactinfo]   --向上移动.向下移动跟这差不多.
    (
    @pkey bigint 
    )
    AS
    BEGIN
    declare @sequence as int
    select @sequence = sequence from tb_contact_info where 主键 = @pkey

    declare @Dpkey as bigint


    select @Dpkey = 主键 from 表名 where  sequence = ( select max(sequence) from  表名 where sequence < @sequence)

    if exists(select top 1 sequence from 表名 where  sequence < @sequence) 
    begin
    update tb_contact_info set sequence = (select top 1 sequence from tb_contact_info as a where a.主键 = @Dpkey) where 主键= @pkey;

    update 表名 set sequence = sequence + 1 where 主键 = @Dpkey ;
    end
    END

    在GridView中添加两列模板列.里面放两个按钮.在RowCommand事件中写下面的代码.
    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(" ", "").Trim(); //这里调用执行存储过程的方法 if (errMsg != "") { Response.Write(clsCommon.Msg("Errors:" + errMsg)); }    //这里再绑定一次.

    在RowDataBound事件中写
    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; }     } }
  • 相关阅读:
    解决一道leetcode算法题的曲折过程及引发的思考
    算法研究:一维多项式求值(秦九韶算法)
    通过HWND获得CWnd指针
    将标题空格替换为 '_' , 并自动复制到剪切板上
    稀疏矩阵操作算法
    微信好友分析之展示好友信息
    微信好友分析之获取好友信息
    爬取当当网的图书信息之结尾
    爬取当当网的图书信息之封装一个工具类
    爬取当当网的图书信息之实体设计
  • 原文地址:https://www.cnblogs.com/huige1004/p/1305742.html
Copyright © 2011-2022 走看看