GridView的RowCommand事件中取得行索引

简介:     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)    ...{        if (e.
     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

目录
相关文章
|
11月前
|
JSON 数据库 数据格式
【datagrid】动态加载列
【datagrid】动态加载列
72 0
C#编程-77:DataGridView绘制行序号
C#编程-77:DataGridView绘制行序号
182 0
C#编程-77:DataGridView绘制行序号
DevExpress GridView 列标题点击事件
GridView有RowCellClick事件,即单元格点击事件,但是针对列标题行以及列标题单元格却没有相应的事件。 在这里使用GridView的MouseDown事件。这里同样使用的是GridHitInfo来获取点击位置的信息,来判断是否在列标题上。GridHitInfo根据鼠标点击的x、y坐标获取该点的相关信息,判断是否点击在列标题行内。 private void
1643 0

热门文章

最新文章