zoukankan      html  css  js  c++  java
  • GridView的RowCommand事件中取得行索引

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        
    {
            
    if (e.Row.RowType == DataControlRowType.DataRow)//如果是为数据行
            {
                ImageButton imgbtnup 
    = (ImageButton)e.Row.Cells[1].FindControl("btnMoveUp");//找控件
                imgbtnup.CommandArgument = e.Row.RowIndex.ToString();//设置与此BUTTON关联的命令参数
                imgbtnup.Visible = e.Row.RowIndex != 0
                ImageButton imgbtndown 
    = (ImageButton)e.Row.Cells[2].FindControl("btnMoveDown");
                imgbtndown.CommandArgument 
    = e.Row.RowIndex.ToString();
                imgbtndown.Visible 
    = e.Row.RowIndex != ((DataSet)((GridView)sender).DataSource).Tables[0].Rows.Count - 1;
            }

        }


        
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        
    {
            
    if (e.CommandName == "MoveUp")
            
    {
                
    int index = Convert.ToInt32(e.CommandArgument);//取的行索引
                DataKey key = this.GridView1.DataKeys[index];
                
    string keyval = key.Value;//取得主键
            }

            
    else if (e.CommandName == "MoveDown")
            
    {
                
    int index = Convert.ToInt32(e.CommandArgument);
                DataKey key 
    = this.GridView1.DataKeys[index];
                
    string keyval = key.Value; 
            }

        }




    文章出处:http://blog.csdn.net/sonce8/archive/2007/09/09/1777777.aspx

  • 相关阅读:
    PHP学习笔记之继承(面向对象三大特性之一)
    php学习笔记之封装练习题
    PHP学习笔记---封装(面向对象三大特性之一)
    PHP学习笔记之面向对象(上)
    php学习笔记之数组遍历练习题1
    php学习笔记数组与数据结构1(数组)
    php学习笔记数组与数据结构1(日期时间函数及遇到的问题解决)
    顺序查找和二分法查找
    冒泡排序
    字符串类型的一些操作处理
  • 原文地址:https://www.cnblogs.com/pyt5208/p/979442.html
Copyright © 2011-2022 走看看