inserting args into a DataList's <td> tag

  • Thread starter Thread starter Steve Klett
  • Start date Start date
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
 
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.
 
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?
 
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'");
 
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
 
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?
 
Back
Top