473,325 Members | 2,608 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,325 software developers and data experts.

DataList Change Row Color OnMouseOver

I want to change the background color of a row in a DataList when the
mouse is moved over a row. This is how I tried but it doesn't change
the background color of a row in the DataList when the mouse is moved
over a row:

<script runat="server">
Sub CreateItem(ByVal obj As Object, ByVal ea As
DataListItemEventArgs)
If (ea.Item.ItemType = ListItemType.Item Or ea.Item.ItemType =
ListItemType.AlternatingItem) Then
ea.Item.Attributes.Add("onmouseover",
"this.style.backgroundColor='pink';")
End If
End Sub
</script>

<form runat="server">
<asp:DataList ID="dlUsers" OnItemCreated="CreateItem" runat="server">
<HeaderTemplate>
<table border="2">
<tr>
<th>Name</th>
<th>EMail</th>
<th>UserName</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr bgcolor="lavender">
<td><%# Container.DataItem("Name") %></td>
<td><%# Container.DataItem("EMail") %></td>
<td><%# Container.DataItem("UserName") %></td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr bgcolor="lightyellow">
<td><%# Container.DataItem("Name") %></td>
<td><%# Container.DataItem("EMail") %></td>
<td><%# Container.DataItem("UserName") %></td>
</tr>
</AlternatingItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:DataList>
</form>

Can someone please guide me on how to change the background color of a
row in a DataList when the mouse is moved over a row in the DataList?

Nov 17 '06 #1
3 8864
Is there any reason you are using a datalist as opposed to a repeater?
Datalist may wrap your item template in some other htmls. Repeater doesn't
add anything. Anyway, if you view the html source with the browser's View
Source option, you should see the whole picture.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
<rn**@rediffmail.comwrote in message
news:11**********************@f16g2000cwb.googlegr oups.com...
>I want to change the background color of a row in a DataList when the
mouse is moved over a row. This is how I tried but it doesn't change
the background color of a row in the DataList when the mouse is moved
over a row:

<script runat="server">
Sub CreateItem(ByVal obj As Object, ByVal ea As
DataListItemEventArgs)
If (ea.Item.ItemType = ListItemType.Item Or ea.Item.ItemType =
ListItemType.AlternatingItem) Then
ea.Item.Attributes.Add("onmouseover",
"this.style.backgroundColor='pink';")
End If
End Sub
</script>

<form runat="server">
<asp:DataList ID="dlUsers" OnItemCreated="CreateItem" runat="server">
<HeaderTemplate>
<table border="2">
<tr>
<th>Name</th>
<th>EMail</th>
<th>UserName</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr bgcolor="lavender">
<td><%# Container.DataItem("Name") %></td>
<td><%# Container.DataItem("EMail") %></td>
<td><%# Container.DataItem("UserName") %></td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr bgcolor="lightyellow">
<td><%# Container.DataItem("Name") %></td>
<td><%# Container.DataItem("EMail") %></td>
<td><%# Container.DataItem("UserName") %></td>
</tr>
</AlternatingItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:DataList>
</form>

Can someone please guide me on how to change the background color of a
row in a DataList when the mouse is moved over a row in the DataList?

Nov 19 '06 #2
Sorry to ask but does that answer my question in anyway (no offence
intended), Eliyahu? I suppose no.

BTW, I have got quite a handful of reasons for using a DataList instead
of a Repeater. I don't mind item templates wrapping either.

Eliyahu Goldin wrote:
Is there any reason you are using a datalist as opposed to a repeater?
Datalist may wrap your item template in some other htmls. Repeater doesn't
add anything. Anyway, if you view the html source with the browser's View
Source option, you should see the whole picture.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
<rn**@rediffmail.comwrote in message
news:11**********************@f16g2000cwb.googlegr oups.com...
I want to change the background color of a row in a DataList when the
mouse is moved over a row. This is how I tried but it doesn't change
the background color of a row in the DataList when the mouse is moved
over a row:

<script runat="server">
Sub CreateItem(ByVal obj As Object, ByVal ea As
DataListItemEventArgs)
If (ea.Item.ItemType = ListItemType.Item Or ea.Item.ItemType =
ListItemType.AlternatingItem) Then
ea.Item.Attributes.Add("onmouseover",
"this.style.backgroundColor='pink';")
End If
End Sub
</script>

<form runat="server">
<asp:DataList ID="dlUsers" OnItemCreated="CreateItem" runat="server">
<HeaderTemplate>
<table border="2">
<tr>
<th>Name</th>
<th>EMail</th>
<th>UserName</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr bgcolor="lavender">
<td><%# Container.DataItem("Name") %></td>
<td><%# Container.DataItem("EMail") %></td>
<td><%# Container.DataItem("UserName") %></td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr bgcolor="lightyellow">
<td><%# Container.DataItem("Name") %></td>
<td><%# Container.DataItem("EMail") %></td>
<td><%# Container.DataItem("UserName") %></td>
</tr>
</AlternatingItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:DataList>
</form>

Can someone please guide me on how to change the background color of a
row in a DataList when the mouse is moved over a row in the DataList?
Nov 19 '06 #3
Sorry if the answer sounds too indirect.

I meant to say that in a case of a DataList you may not have a clear idea
what html is produced for the item. Therefore, your ea.Item.Attributes.Add
statement may assign the attribute to not what you think. If you view the
html source, you will see exactly what your attribute got attached to and
thus get a better idea what the problem is.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
<rn**@rediffmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
Sorry to ask but does that answer my question in anyway (no offence
intended), Eliyahu? I suppose no.

BTW, I have got quite a handful of reasons for using a DataList instead
of a Repeater. I don't mind item templates wrapping either.

Eliyahu Goldin wrote:
>Is there any reason you are using a datalist as opposed to a repeater?
Datalist may wrap your item template in some other htmls. Repeater
doesn't
add anything. Anyway, if you view the html source with the browser's View
Source option, you should see the whole picture.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
<rn**@rediffmail.comwrote in message
news:11**********************@f16g2000cwb.googleg roups.com...
>I want to change the background color of a row in a DataList when the
mouse is moved over a row. This is how I tried but it doesn't change
the background color of a row in the DataList when the mouse is moved
over a row:

<script runat="server">
Sub CreateItem(ByVal obj As Object, ByVal ea As
DataListItemEventArgs)
If (ea.Item.ItemType = ListItemType.Item Or ea.Item.ItemType =
ListItemType.AlternatingItem) Then
ea.Item.Attributes.Add("onmouseover",
"this.style.backgroundColor='pink';")
End If
End Sub
</script>

<form runat="server">
<asp:DataList ID="dlUsers" OnItemCreated="CreateItem" runat="server">
<HeaderTemplate>
<table border="2">
<tr>
<th>Name</th>
<th>EMail</th>
<th>UserName</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr bgcolor="lavender">
<td><%# Container.DataItem("Name") %></td>
<td><%# Container.DataItem("EMail") %></td>
<td><%# Container.DataItem("UserName") %></td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr bgcolor="lightyellow">
<td><%# Container.DataItem("Name") %></td>
<td><%# Container.DataItem("EMail") %></td>
<td><%# Container.DataItem("UserName") %></td>
</tr>
</AlternatingItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:DataList>
</form>

Can someone please guide me on how to change the background color of a
row in a DataList when the mouse is moved over a row in the DataList?

Nov 20 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Steve Klett | last post by:
I would like to have DHTML on my DataList so that when I hover over a cell, it will change colors. I can't find a way to get onMouseOver into the generated <td> from a DataList. There must be ...
1
by: Steve Klett | last post by:
Hi- Is there anyone that knows or maybe even a MS person that would like to discuss workarounds for the DataList not respecting Attributes.Add() I need to get onMouseOver and onMouseLeave into...
10
by: Bharat | last post by:
Hi Folks, Suppose I have two link button on a page (say lnkBtn1 and lnkBtn2). On the click event of the lnkbtn1 I have to add a dynamically created control. And On the click event of the lnkBtn2 I...
0
by: Scott Reynolds | last post by:
Hello! I am trying to add onMouseOver attribute to each DataList item, but can't get it work... Somebody said that this is a bug in DataList control, if so, is there a workaround for this? ...
2
by: IGotYourDotNet | last post by:
Can anyone tell me how to find a table within a datalist? I can find the labels and textboxes in the dl and change the formatting based on the data, but I can't find the table in the DL. Can anyone...
4
by: Miguel Dias Moura | last post by:
Hello, I created a datalist in an ASP.Net / VB page. I display the image and price of a few products. When a user clicks an image I want to load the page "detail.aspx?number=id" and send the...
5
by: Ryan Moore | last post by:
I am trying to modify the onMouseOver attribute of a <td> cell created by a DataList... according to ...
7
by: tshad | last post by:
Is there a way to move a row in a Datalist up or down without having to re-read the data? I have a datalist which has embedded Datagrids in it. I want to allow the user to move a row up or down...
1
by: WB | last post by:
Hi, I would like to do something like this page: http://www.stocklayouts.com/Products/Postcard/Postcard-Template-Design-Library.aspx?kwid=38 Notice when you mouse-over any of the icons under...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.