您的位置:首页 > 其它

Gridview的RowCommand事件中获取RowIndex的方法

2010-11-28 15:57 597 查看
第一种:

GridViewRow currRow = (GridViewRow)((LinkButton)e.CommandSource).Parent.Parent;

currRow.RowIndex取得当前行

currRow.Cells[0].Text.Trim()取得当前行的列值

第二种:

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
int rowIndex = -1;
GridViewRow row = null;
switch (e.CommandName)

case "Command1": // 模板列
// 对于模板列内的按钮,我们需要显示绑定行索引到按钮的 CommandArgument 属性
// 以获取触发事件的行信息
rowIndex = Convert.ToInt32(e.CommandArgument);
row = GridView1.Rows[rowIndex];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐