积极答复者
gridview点击行事件中可以添加自定义的方法吗?

问题
-
protected void gvshow_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//当鼠标停留时更改背景色
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#8F8F8F'");
//当鼠标移开时还原背景色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
Label lbllh = e.Row.FindControl("lblpn") as Label;if (lbllh !=null)
{
e.Row.Attributes.Add("onclick", "getValue('"+lbllh.Text+"');");
}
//变小手
e.Row.Attributes["style"] = "Cursor:hand";}
}--------------------------------后台代码--------------------------------
--------------------------------前台代码--------------------------------
<script type="text/javascript" language="javascript">
function showData() {
var show = document.getElementById("pro");
show.style.display = "block";
}function getValue(para1) {
document.getElementById("lblpn").value = para1;
}
</script>我现在添加的单击事件没有反应,不过我弹出的时候有值. 和郁闷
答案
全部回复
-
if (lbllh !=null)
{
e.Row.Attributes.Add("onclick", "getValue(lblh.ClientID, '"+lbllh.Text+"');");
}function getValue(lblid,para1) {
document.getElementById(lblid).value = para1;
}
http://feiyun0112.cnblogs.com/