GridView with clickable rows

If you need to have a GridView with rows that you can click on you will need to set the onClick event for each row.

Here is a code sample for the RowDataBound event of a GridView.
This examples pulls the value of cell 0 and appends it to the url.

protected void grd_RowDataBound(object sender, GridViewRowEventArgs e)
{
GridView grid = (GridView)sender as GridView;

//Only format data rows
if (e.Row.RowType == DataControlRowType.DataRow)
{

string urlLink = “Link?number=” + e.Row.Cells[0].Text.ToString();
e.Row.Attributes[“onClick”] = “location.href='” + urlLink + “‘”;

}
}

Advertisements

One thought on “GridView with clickable rows

Got something to add?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s