HI
Follow these steps.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="100%"
OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField HeaderText="SomeColumn" DataField="SomeColumn" />
</Columns>
</asp:GridView>
1) create a
OnRowDataBound
event to the grid view as above.
2) in the server event add
onclick
event to the rows as follows
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string primaryKey = DataBinder.Eval(e.Row.DataItem, "PrimaryKeyID") + "";
e.Row.Attributes.Add("onclick", "opennewwindow('" + primaryKey + "')");
}
}
3) add
javascript
to open a new window , by passing the
primary key ID
as parameter.
<script type="text/javascript">
var opennewwindow = function (primarykey) {
alert(primarykey);
window.location = "Job.aspx?primarykey=" + primarykey;
}
</script>
sample input to run the above:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add("PrimaryKeyID", typeof(int));
dt.Columns.Add("SomeColumn", typeof(string));
dt.Rows.Add(1,"aaaaaaaa");
dt.Rows.Add(2,"bbbbbbbbb");
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
read the query string values in next page as
public partial class Job : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
int primarykey = Convert.ToInt32(Request.QueryString["primarykey"]);
}
}