关于gridview事件

时间:2013-11-11 06:34:33

标签: c# asp.net gridview

我正在使用以下代码:

protected void gvDetails_RowCreated(object sender, GridViewRowEventArgs e)
 {
    e.Row.Attributes["ondblclick"] = "location.href='CustomerInfo.aspx?page=0&Custid=" + Convert.ToString(e.Row.FindControl("hdfCust_Id")) + "'";

 }

所以当我双击gridview时,它会将我重定向到下一页并给出错误。 Custid的值如下:

Custid=System.Web.UI.WebControls.HiddenField

1 个答案:

答案 0 :(得分:3)

你需要

 ((HiddenFiled)e.Row.FindControl("hdfCust_Id")).Value

结合以上

e.Row.Attributes["ondblclick"] = "location.href='CustomerInfo.aspx?page=0&Custid=" 
      + ((HiddenField)e.Row.FindControl("hdfCust_Id")).Value + "'";

编辑1

Convert.ToString(e.Row.FindControl("hdfCust_Id"))输出为System.Web.UI.WebControls.HiddenField
((HiddenField)e.Row.FindControl("hdfCust_Id")).Value将是您所需的值