Thursday, July 17, 2008

GridViewRow as Hyperlink


This is a simple technique used in the RowDataBound event of a GridView so that its Entire Row acts as a HyperLink.
For Visual effects styles are applied at mouseover and mouseout.
The cursor is also given a hand like appearance to show the row is a hyperlink


protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onmouseover"] = "this.style.color='DodgerBlue';this.style.cursor='hand';";
e.Row.Attributes["onmouseout"] = "this.style.color='Black';";
e.Row.Attributes["onclick"] = "window.navigate('NavigatedPage.aspx?id=" + e.Row.RowIndex + "')";
// can send anything as querystring
}
}

Related Posts :



1 comments on "GridViewRow as Hyperlink"

Add your comment. Please don't spam!
Subscribe in a Reader
Rajju on August 4, 2009 at 11:57 PM said...

Thanks!! it works a part only but cannt redirect to next page on onclick .can u give more solution.

Post a Comment