您的位置:首页 > 其它

gridview鼠标双击事件(跳转至新页面并传值)单击获取值

2011-12-24 09:46 344 查看
gridview添加RowDataBound事件,并设置DataKeyName为绑定数据的主键

protected void gridview1_RowDataBound(object sender, GridViewRowEventArgs e)

{

//判断选择的是否是数据行

if (e.Row.RowType == DataControlRowType.DataRow)

{

int SId = Convert.ToInt32(this.gridview1.DataKeys[e.Row.RowIndex].Value);//获取DateKeyName的值

//鼠标在某行,变色

e.Row.Attributes.Add("onmouseover", "c=style.backgroundColor;style.backgroundColor='yellow'");

e.Row.Attributes.Add("onmouseout", "style.backgroundColor=c");

//添加双击事件(跳转至新页面)

e.Row.Attributes.Add("ondblclick", "window.open(a.aspx?SId=" + SId + "');");

//添加单击事件

e.Row.Attributes["onclick"] = ClientScript.GetPostBackEventReference(gridview1,"Select$"+e.Row.RowIndex.ToString());

}

双击后a页面接收sid

int sid = Convert.ToInt32(Request.QueryString["SId"]);

单击后获取单击行的DataKey

int value = Convert.ToInt32(this.gridview1.DataKeys[gridview1.SelectedIndex].Value);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: