GridViewCommandEventArgs”并不包含“NewSelectedIndex”的定义

来源:百度知道 编辑:UC知道 时间:2024/05/21 08:01:26
我在gridview里用模板列创建一个隐藏列作为索引,然后如下调用
public void userlist_RowCommand(Object sender, GridViewCommandEventArgs e)
{
// If multiple ButtonField column fields are used, use the
// CommandName property to determine which button was clicked.
if (e.CommandName == "del")
{
HiddenField user_id = (HiddenField)this.userlist.Rows[e.NewSelectedIndex].Cells[0].FindControl("user_id");
}
系统提示 “System.Web.UI.WebControls.GridViewCommandEventArgs”并不包含“NewSelectedIndex”的定义,该怎么解决,请高人指教
感谢lackyhuang,sq_zhuyi,sq_zhuyi的回答

HiddenField user_id = (HiddenField)this.userlist.Rows[Convert.ToInt32(e.CommandArgument)].Cells[0].FindControl("user_id");

前面2位说的应该可以,但是记得需要在前台给e.CommandArgument赋值,赋上ROWINDEX。。。

但是如果你的e.CommandArgument需要存放别的值

那么用别的方法同样可以在后台得到GRIDVIEW内这一整行数据的内容,代码如下
string userId=((GridViewRow)((Button)e.CommandSource).NamingContainer).FindControl("user_id");

int index = Convert.ToInt32(e.CommandArgument);