Select gridwiev on mouse click in

Is it possible to select gridview row on mouse click on row (like in winforms), idea is that user can click anywhere on row and to select clicked row (of course color of selected row must change on selection)
Who is Participating?
do you want to do it on the client side? I had written an entire article to do this. It uses JQuery. Maybe it might help you...

go to and look at the blog post about Gridview.

kahvedzicAuthor Commented:
As much as I can understand from your post this is code for changing row colors in gridview. I first need to be able to select gridview row without select button, just click anywhere on row.
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Akin DeluI’m a software engineer, tech enthusiast and UI/UX lover. Commented:
this is a sample code
in your server side code

Protected Sub GridView1_RowCreated(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated
        If e.Row.RowType = DataControlRowType.DataRow Then
            e.Row.Attributes.Add("onclick", "if('rgb(193, 210, 238)'){'rgb(255, 255, 255)';}else{'rgb(193, 210, 238)';}")
        End If
    End Sub

protected void GridView1_RowCreated(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
            if (e.Row.RowType == DataControlRowType.DataRow)
                e.Row.Attributes.Add("onclick", "if('rgb(193, 210, 238)'){'rgb(255, 255, 255)';}else{'rgb(193, 210, 238)';}");
Use RowDataBound of grid.

protected void Grid1_RowDataBound(object sender, GridViewRowEventArgs e)
      e.Row.Attributes.Add("onclick", " = 'red';");

Open in new window

kahvedzicAuthor Commented:
This is what I did:

    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            e.Row.Attributes.Add("onmouseover", "'hand';")
            e.Row.Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(sender, "Select$" + e.Row.RowIndex.ToString))
        End If
    End Sub

and in html code:
created new style
    <style type="text/css">    

for selected button that was in gridview:
<asp:CommandField ButtonType="Image" ShowSelectButton="True" ItemStyle-CssClass ="HiddenColumn" HeaderStyle-CssClass ="HiddenColumn" SelectImageUrl="~/Images/check.gif" >

This is working, but I have on GridView1_SelectedIndexChanged event


but it is not working, my GridView is in asp Panel with vertical scroll bar, and when I select  row that I must scroll to see focus is not working.
kahvedzicAuthor Commented:
ok I will take a look, thanks
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.