日期:2014-05-18  浏览次数:21032 次

如何实现gridview单击某一行链接到相关网页
如果

注意 是 单击行 而不是 单击行里的 某项

另外 要求是 链接 <a href 地址>


马上给分

------解决方案--------------------
C# code

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
   { 
   
   e.Row.Attributes["onclick"] = String.Format("JavaScript:window.open({0})", "http://www.csdn.net"); 
     }

------解决方案--------------------
同意楼上。
C# code

 e.Row.Attributes["onclick"] = string.Format("window.open('{0}');", "http://www.csdn.net");
 e.Row.Attributes["onmouseover"] = "this.style.backgroundColor='Maroon';this.style.color='White';this.style.cursor='hand';";
 e.Row.Attributes["onmouseout"] = "this.style.backgroundColor='White';this.style.color='Black';"

------解决方案--------------------
另外最好是在
if(e.Row.RowType==DataControlRowType.DataRow)
{
//在这里为行添加css属性。 
}
------解决方案--------------------
探讨
C# code
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{

e.Row.Attributes["onclick"] = String.Format("JavaScript:window.open({0})", "http://www.csdn.net");
}





不知道你为什么非要 <a href>? 单击行也只能是给这个row加上事件然后javascript去做.这个行本来不可能被 <a >... </a>包含起来. 说白了给row加事件最终也只是给输入的table 的 row加上事件…

------解决方案--------------------
C# code
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
   { 
   
   e.Row.Attributes["onclick"] = String.Format("JavaScript:location.href='http://www.csdn.net'); 
   }

------解决方案--------------------
<asp:HyperLinkField DataNavigateUrlFields="detaineeId" DataNavigateUrlFormatString="../InAndOutCalaboose/InCalabooseShow.aspx?Id={0}"
Text="查 看"/>

加这句在gridview里面,哥子,思想太僵化了是卜行滴~~~,那个路径自己改哈

要不就得这样,好像也可以
protected void gdvComplice_RowDataBound(object sender, GridViewRowEventArgs e)
{
//如果是绑定数据行 
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("ondblclick", "window.location.href='InCalaboose.aspx?Id=" + this.gridInCalaBooseList.DataKeys[e.Row.RowIndex].Value + "'");
}
}