I have a gridview that has a commandfield in it at the start of each row.
Here is the commandfield.
<asp:CommandField SelectText="Detail" ShowSelectButton="true"
ButtonType="Link" />
I need to open a webform in another window from this and pass a parameter
of
the ID for the record in the selected row. Preference would be to have
this
occur on the client side. How would this be accomplished?
Samples/examples
links are welcomed.
Firstly, I wouldn't use a separate column for this - all that does is waste
space on the screen. Instead, I'd wire up a click event on the GridView
itself so that all the users have to do is click the row:
protected void MyGridView_RowDataBound(object sender, GridViewRowEventArgs
e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick",
ClientScript.GetPostBackEventReference(MyGridView, "Select$" +
e.Row.RowIndex.ToString()));
e.Row.Style["cursor"] = "pointer";
/* or, if you want only certain cells within
each row to respond to the click event
for (int intCell = 1; intCell < 4; intCell++)
{
e.Row.Cells[intCell].Attributes.Add("onclick",
ClientScript.GetPostBackEventReference(MyGridView, "Select$" +
e.Row.RowIndex.ToString()));
e.Row.Cells[intCell].Style["cursor"] = "pointer";
}
*/
}
}
protected void MyGridView_SelectedIndexChanged(object sender, EventArgs e)
{
// do something with MyGridView.SelectedValue.ToString();
}
Secondly, I absolutely would not do anything which opens another window. For
one thing, depending on how the rest of the application is written and
deployed, and what browser the users are using, this is likely to trigger
the popup blocker. Also, there has been instances of the child window losing
contact with the main window's Session or, in some cases, even creating a
new Session. Instead, I'd use the AJAX modal popup extender:
http://www.google.co.uk/search?aq=0&oq=AJAX+moda&sourceid=chrome&ie=UTF-8&q=ajax+modal+popup
That would mean that you wouldn't need to pass anything anywhere, as the
modal popup would have access to the entire page anyway, so anything it
needed to know it could simply look up...