前台页面: gridview设置DataKeyNames为传值到新页面的关键字
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="BoatNo"
Font-Size="14px" CellPadding="4" ForeColor="#333333" GridLines="Both" AllowSorting="true"
OnRowDataBound="GridView1_RowDataBound" CssClass="Admin_Table"
HorizontalAlign="Center" VerticalAlign="Middle" >
后台页面:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)//判定当前的行是否属于datarow类型的行
{ string SId = (this.GridView1.DataKeys[e.Row.RowIndex].Value).ToString();//获取DateKeyName的值
e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#99ccff',this.style.fontWeight='';"); //当鼠标放上去的时候 先保存当前行的背景颜色 并给附颜色 e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style"); //当鼠标离开的时候 将背景颜色还原的以前的颜色
e.Row.Attributes.Add("ondblclick", "window.location='BoatSearch.aspx?key=" + SId + "';");//双击行弹出新页面并传值。
}
}