473,386 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Gridview highlight row and mouseover & mouseout attributes

40
Hi,

i have a gridview i need to highlight row on mouse over on the row and highlight the row when clicked , this time mouse over on other rows should not happen.
i have done with mouse over n out and also higglight row on clicking. But dont know how to perform mouse over on other rows should not happen when a row is highlighted.

This is my code

Expand|Select|Wrap|Line Numbers
  1. aspx.cs
  2.  
  3. protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
  4.     {
  5.  
  6.  
  7.         if (e.Row.RowType == DataControlRowType.DataRow)
  8.         {
  9.  
  10.  
  11.                 e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#00FF00';");
  12.                 if (e.Row.RowIndex % 2 == 0)
  13.                 { // even
  14.                     e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FF8040';");
  15.                 } // odd
  16.                 else
  17.                 {
  18.                     e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FF8040';");
  19.                 }
  20.  
  21.                 e.Row.Attributes.Add("onclick", "onGridViewRowSelected('" + id.ToString() + "')");
  22.  
  23.         }
  24.        id++;
  25.  
  26.  
  27.     }
  28.  
  29. aspx page
  30.  
  31. <script language="javascript" type="text/javascript">
  32.     var gridViewCtlId = '<%=GridView1.ClientID%>';
  33.     var gridViewCtl = null;
  34.     var curSelRow = null;
  35.     function getGridViewControl()
  36.     {
  37.         if (null == gridViewCtl)
  38.         {
  39.             gridViewCtl = document.getElementById(gridViewCtlId);
  40.         }
  41.     }
  42.  
  43.     function onGridViewRowSelected(rowIdx)
  44.     {
  45.         var selRow = getSelectedRow(rowIdx);
  46.         if (curSelRow != null)
  47.         {
  48.             curSelRow.style.backgroundColor = '#ffffff';
  49.         }
  50.  
  51.         if (null != selRow)
  52.         {
  53.             curSelRow = selRow;
  54.             curSelRow.style.backgroundColor = '#ff0022';
  55.         }
  56.     }
  57.  
  58.     function getSelectedRow(rowIdx)
  59.     {
  60.         getGridViewControl();
  61.         if (null != gridViewCtl)
  62.         {
  63.             return gridViewCtl.rows[rowIdx];
  64.         }
  65.         return null;
  66.     }
  67. </script>            
  68. <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
  69.         onrowcreated="GridView1_RowCreated">
  70.        <Columns>
  71.         <asp:TemplateField HeaderText="Name">
  72.             <ItemTemplate>
  73.                 <%# Eval("Name")%>
  74.              </ItemTemplate>
  75.         </asp:TemplateField>
  76.          <asp:TemplateField HeaderText="Age">
  77.             <ItemTemplate>
  78.                 <%# Eval("Age")%>
  79.             </ItemTemplate>
  80.         </asp:TemplateField>
  81.          <asp:BoundField HeaderText="Gender" DataField="Gender"/>
  82.  
  83.  
  84.         </Columns>
  85.  
  86. </asp:GridView>

please help me asap...
thanks in advance
May 21 '10 #1
3 5065
semomaniz
210 Expert 100+
This might help

Expand|Select|Wrap|Line Numbers
  1. e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='Silver'");
  2.  
  3. e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='White'");
  4.  
  5.  
May 21 '10 #2
semomaniz
210 Expert 100+
never mind i didnt read the entire code you already have the done
May 21 '10 #3
Frinavale
9,735 Expert Mod 8TB
Well, in this case you only want to apply the JavaScript to the row if the row is a DataRow, if the GridView's selected index is less than 0 (not selected), and perhapse if the GridView's edit index is also less than 0 (not editing).

So you should change your if statement to:
Expand|Select|Wrap|Line Numbers
  1.  if (e.Row.RowType == DataControlRowType.DataRow && GridView1.SelectedIndex<0 && GridView1.EditIndex<0)
-Frinny
May 21 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Matt Colegrove | last post by:
Is there a way to apply a "mouseover" command to the cell level of a GridView? I can do it at the row level, but I want to be able to do it at the cell level. I was able to do it with the...
1
by: vikraman | last post by:
Request the script for Mouseover dispy of text at specific coordinats of an image/body and Mouseout disply of original image/body
3
by: vikraman | last post by:
I have a problem. See the Mouseover event below <head> <script type="text/javascript"> function writeText(txt) { document.getElementById("x").innerHTML=txt }
4
by: anj | last post by:
please provide me a syntax / command on how to create this tooltip (mouseover and mouseout) complete command. so i can apply it on my project.. please help me.. tnx
3
by: =?Utf-8?B?TTFpUw==?= | last post by:
I have a GridView control with a template column that I use to display my record data. I’ve included an EditItemTemplate with textboxes bound to the GridView for editing. On my SqlDataSource I...
0
by: =?Utf-8?B?SGFyZHkgV2FuZw==?= | last post by:
Hi all, I am building a web site with theme support, under each theme's folder there are some images. Some of my images need to be skinned, I know I can build a skin file with line like ...
2
by: james_027 | last post by:
hi everyone, I am now in chapter 5 of Dive Into Python and I have some question about it. From what I understand in the book is you define class attributes & data attributes like this in python...
0
by: mike0870 | last post by:
Hi, I've been at this one for hours and cannot not find any posts of anyone having the same problem. Ther scenario is, I need to fill a drop down box with a value in the grid row to pass to the...
2
by: -Steve- | last post by:
I have the need to change the text of certain rows to red based on the proximity of a date in one of the columns. What's the best way to go about this?
3
by: Nathan Sokalski | last post by:
I am adding an onmouseover attribute using the Attributes.Add() method, and the String I am using for the value contains the & character. However, when rendered the & is converted to the HTML...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.