inserting args into a DataList's <td> tag

S

Steve Klett

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 way to do this.... I am just
missing it I suppose.

Anyone know?

Thanks,
Steve
 
C

Chris Bower

I'm just guessing here (because I haven't tried it myself) but you might try
handling the ItemCreated event and processing it there... Something like
this:

Protected Sub myDataList_ItemCreated(sender as object, e as eventargs)
handles myDataList.ItemCreated
If e.Item.Type = Item or e.Item.Type = AlternatingItem Then
dim myItem as DataListItem = CType(e.Item, DataListItem)
myItem.Attributes("onMouseOver") = "javascript:none;"
End If
End Sub

Keep in mind that I just typed this in my news client and not in the IDE, so
its not guaranteed to work, but it may give you some ideas.
 
S

Steve Klett

Hi Chris,

Thanks for the reply.

Yeah, I found that I can use Attributes.Add() to do what I want. Weird
thing is... I have implemented it, but in the result HTML the attributes
aren't there. I've checked my schema, it's IE 5, so it's not that.

I've set a breakpoint in the DataBind event to see if it is actually firing,
it is. I have added this code to add the attributes. I suspect that my
DHTML syntax is off, but I should at least see the bad syntax in the result
HTML, but it's not there.
e.Item.Attributes.Add("onMouseEnter", "style.color = 'red'");



Any ideas?
 
C

Chris Bower

Hmm... Sounds like it should work. I don't know why it would make a
difference, but try not doing the .Add and just accessing the
AttributesCollection directly:
e.Item.Attributes("onMouseEnter","style.color = 'red'");
 
S

Steve Klett

That doesn't work either. This is odd. I don't see what I could be
missing.....
 
S

Steve Klett

If I use a dataGrid, it works fine. I think with a DataList you can't
access the cell.... DataGrid exposes cells collection, then you can do it,
but not the DataList
 
C

Chris Bower

Ahh, that makes sense. Odd though. Anyone from MS care to comment on why
that is?
 
S

Steve Klett

I did this just to see if anything weird popped up
e.Item.Attributes.Add("onMouseEnter", "javascript:alert('test');");

IEnumerator iT = e.Item.Attributes.Keys.GetEnumerator();

while(iT.MoveNext())

{

Response.Write((string)iT.Current);

}


sure enough, the attributes are being added, just not rendered. Bummer.
Yeah, MS.. any word, suggestions, work arounds?
 

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

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top