Highlight a row from GridView without the built-in SELECT

1. Create a style for the highlight and no show:

<style type="text/css">

.SelectedRowStyle {background-color: yellow;}




2.1 And add the style to the griview:  SelectedRowStyle-CssClass="SelectedRowStyle"

2.2 And add the noshow style to the SELECT Commandfield:

<asp:CommandField SelectText ="Select" ShowSelectButton="true" ItemStyle-CssClass = "Noshow" HeaderStyle-CssClass ="Noshow" />

3. Register a postback javascript through OnRowDataBound event:

protected void GridView1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)

        if (e.Row.RowType == DataControlRowType.DataRow) {
            e.Row.Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(GridView1, "Select$" + e.Row.RowIndex.ToString()));


Leave a Reply

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