Highlight a clicked row in a gridview linked to a css

C

Chris

I am using a gridview with alternating row color. The gridview is gets its
attributes from a stylesheet.
I want to highlight a row when the user clicks on it. I did this with client
side script and it worked fine until I attached the view to a stylesheet.
It seems like the stylesheet has priority over my script.
My script was just::
oRowClicked.bgColor="yellow";

but it no longer works.

Anyone know how I can handle row clicked highlighting?

TIA,

Chris
 
S

Steven Cheng[MSFT]

Hello Chris,

As for the stylesheet you applied on the page, what element or class have
you defined in it that override your client-script setting on your gridview
row? Based on my experience, you can use client-side script to
programmatically manipulate the gridview row's css class. You can predefine
those class in the css style sheet(with any style attributes you like, such
as background color .....). e.g.

You first set a default CSSClass for your gridview row as below:
=========================
asp:GridView ID="GridView1" runat="server"............................ >
<RowStyle CssClass="gv_row" />

===========================================

And you can add script handler for your gridview row to change its css
class(instead of individual properties).

==================
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onmouseover"] =
"this.className='gv_row_hover';";
e.Row.Attributes["onmouseout"] = "this.className='gv_row';";
}
}
===================

Does this help?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Steven Cheng[MSFT]

Hello Chris,

Have you resolved this problem or does the information in my last reply
helps you a little on this? If you have any further questions or anything
else we can help, please feel free to let me know.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



This posting is provided "AS IS" with no warranties, and confers no rights.
 
C

Chris

Sorry Steven,
I didn't see your reply until just now. Somehow my newsreader was not
picking up everything and I thought this question went unanswered.
I still have the problem and I'm going to apply what you suggest.
I'll reply back with the result.
Thank you ,

Chris
 
C

Chris

Hi Steven,
What I found is that I had a td style in my css overriding my row level
backcolor.

In my css I had
..gridview td {}

where the background: was set. If I remove the background setting everything
will work fine but if I add it back I cannot override the background at the
row level.

This is what stopped the highlighting from working.

I like your class swap method instead of the bgColor I was changing in my
script. I'm going to revise my code to use your technique.

Thank you for your help.

Chris
 
S

Steven Cheng[MSFT]

Thanks for your followup Chris,

Glad that you've figured out the root cause.

Wish you good luck!

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top