No change to the aspx UI page. I just modified the code behind page. Please have look in the RowDataBound method.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Demo : System.Web.UI.Page
{
List<user> userList = new List<user>();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
userList.Add(new User() { UserName = "Alex" });
userList.Add(new User() { UserName = "Bob" });
userList.Add(new User() { UserName = "Jeniffer" });
GridView1.DataSource = userList;
GridView1.DataBind();
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton link = e.Row.FindControl("LinkButton1") as LinkButton;
string name = e.Row.Cells[0].Text;
link.Attributes["onclick"] = "return popwin('" + name + "')";
}
}
}
public class User
{
public string UserName { get; set; }
}