62,025
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Demo1</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound">
</asp:GridView>
</div>
</form>
</body>
</html>
public partial class Demo1 : System.Web.UI.Page
{
public class Employee
{
public string EmpID { set; get; }
public string EmpName { set; get; }
}
protected void Page_Load(object sender, EventArgs e)
{
this.GridView1.DataSource = new System.Collections.Generic.List<Employee>()
{
new Employee(){ EmpID="S001", EmpName="张三"},
new Employee(){ EmpID="S002", EmpName="李四"},
new Employee(){ EmpID="S003", EmpName="王五"},
new Employee(){ EmpID="S004", EmpName="赵六"},
new Employee(){ EmpID="S005", EmpName="小七"}
};
this.GridView1.DataBind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("ondblclick", "window.open('DetailView.aspx?EmpID=" + DataBinder.Eval(e.Row.DataItem, "EmpID") + "');");
}
}
}
/// <summary>
/// 员工编号
/// </summary>
public string EmpID
{
get { return Request.QueryString["EmpID"] ?? string.Empty; }
}
///后台在数据绑定时注册一个JavaScript方法///////////
protected void gvDraft_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick", "return openLink('" + url + "')");
}
}
////////前台增加一个相应的JS方法//////////////
function openLink(url) {
window.open("MonthTargetAdjust.aspx?" + url, "1", "resizable=yes,toolbar=no,statusbar=no,menubar=no,location=no,scrollbars=yes,titlebar=no,width:900,height:700");
}