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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
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)';}");
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

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.
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.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kahvedzicAuthor Commented:
ok I will take a look, thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.