Select gridwiev on mouse click in asp.net

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)
LVL 1
kahvedzicAsked:
Who is Participating?

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

x
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.
0
Akin DeluI’m a software engineer, tech enthusiast and UI/UX lover. Commented:
this is a sample code
=====================
in your server side code

VB
=====
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(this.style.backgroundColor=='rgb(193, 210, 238)'){this.style.backgroundColor='rgb(255, 255, 255)';}else{this.style.backgroundColor='rgb(193, 210, 238)';}")
        End If
    End Sub

C#
===
protected void GridView1_RowCreated(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onclick", "if(this.style.backgroundColor=='rgb(193, 210, 238)'){this.style.backgroundColor='rgb(255, 255, 255)';}else{this.style.backgroundColor='rgb(193, 210, 238)';}");
            }
        }
0
C++ 11 Fundamentals

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

rajapandian_81Commented:
Use RowDataBound of grid.

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

Open in new window

0
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", "this.style.cursor='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">    
        .HiddenColumn{display:none;}
    </style>

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

GridView1.SelectedRow.Focus()

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.
0
sujeshvaCommented:
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 http://sujesharukil.blogspot.com and look at the blog post about Gridview.

-Suj
0

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