Here is an example implementation. This binds some sample data in the GridView and each row has a "Detail" link. When clicked, the "Detail" link opens a popup window with the Id as parameter.
Basically, the "onclick" javascript attribute is bound with the javascript method popupwin() with the Id parameter in the
RowDataBound event of the GridView (See CodeBehind code)
The Markup:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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 id="Head1" runat="server">
<title></title>
<script language="javascript">
function popwin(id) {
var nw = window.open("", "window", "width=200,height=300,scrollbar=yes");
nw.location.href = "default3.aspx?id " + id;
nw = null;
return false;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
Width="215px" onrowdatabound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"
Text="Detail"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</div>
</form>
</body>
</html>
The CodeBehind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
public class Person
{
public int Id
{
get;
set;
}
public string Name
{
get;
set;
}
public Person(int Id, string Name)
{
this.Id = Id;
this.Name = Name;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
IList items = new ArrayList();
items.Add(new Person(1, "Peter"));
items.Add(new Person(2, "John"));
items.Add(new Person(3, "Shubho"));
GridView1.DataSource = items;
GridView1.DataBind();
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton link = e.Row.FindControl("LinkButton1") as LinkButton;
link.Attributes["onclick"] = "return popwin(" + ((Person)e.Row.DataItem).Id + ")";
}
}
}
Hope this will help you implementing your desired functionality.