Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to change the color of the row in GridView OnMouseClick

Posted on 2007-07-31
7
Medium Priority
?
1,151 Views
Last Modified: 2008-01-09
Hello experts,
How to change the color of the row in GridView OnMouseClick (Visual C# ASP.NET web application)
I implemented this example:
http://gridviewguy.com/ArticleDetails.aspx?articleID=174
and  it's working, but in this example row changes the color on click,
and it turns back to default color when you click again.
But I need this scenario: when you click/select one row1 it will become yellow (in this case),
and after clicking another row2, the previous selected row1 will turn back to default color without clicking it again, and of course, the new clicked row2 will become yellow. So, only one row can be colored at the same time because I want to see which row is selected.

Thanks
0
Comment
Question by:itproem
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 13

Expert Comment

by:joechina
ID: 19600327
In your case, the best way is to set

SelectedRowStyle-xxx properties of GridView. (I would suggest you to use css or skin file)

Then in your code, just specify which row is current selected.
SelectedIndex or SelectedRow property could be used.
0
 
LVL 12

Expert Comment

by:Pra4444
ID: 19600351
see whether the following example can work for you..

do you want only mouseclick or will mouseover and mouseout work for you??

http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_22690077.html
0
 

Author Comment

by:itproem
ID: 19600410
I really need mouseclick
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Accepted Solution

by:
Pra4444 earned 1500 total points
ID: 19600460
I think this example should work the way you want...

http://www.netomatix.com/development/gridviewrowselectedstyle.aspx
0
 

Author Comment

by:itproem
ID: 19600489
If I'll use SelectedRowStyle-xxx in XYX procedure, should I then use OnSelectedIndexChanged ="XYX" ?
0
 
LVL 13

Expert Comment

by:joechina
ID: 19600512
No.
Just in your rowcommand event or mouseclick event specify

yourGridView.SelectedIndex = Convert.ToInt32(e.CommandArgument);
(or something like it depends on the event)  (e.CommandArgument is from rowcommand event)
0
 
LVL 14

Expert Comment

by:chinu1310
ID: 19600738
Static and rollover effect code

Statically you can define in your gridview.


 <SelectedRowStyle BackColor="#C0D2DD" />

For rollover color change do like this.

protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{



if (e.Row.RowType == DataControlRowType.DataRow)
{

e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='dee0aa'");

e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='ebeccd'");


}
}
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month20 days, 15 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question