I ran into the same problem with my control extending the DataList. I think
that the adding the attributes to the DataListItem wont work. What I ended
up doing was iterating over the DataListItem.Controls collection in the
OnPreRender event (CreateItem is too early). The first item in the
collection is not a WebControl and will not accept the attributes, however if
your template displays a control that resolves to a WebControl you can apply
the attribute. Here's an example of what I did.
dim ctl as Control
dim webctl as WebControl
For Each ctl in item.Controls
Try
webctl = DirectCast(ctl,WebControl)
webctl.Attributes.Add("onmouseover",MyValue1)
Catch
End Try
Next
That was my solution to the problem. If you come up with a better way
please let me know. Also, did you run into anything like the 'active schema
does not support.." problem I posted on the post right above this one?
Any way, hope this helps!
Cheers!
[quoted text, click to view] "J'son" wrote:
> Guys,
>
> I have created a custom class that derives from DataList so that I can
> add some custom client side functionality into each new item row
> (<td>). Heres the class in its simplest form:
>
> public class MyDataList : DataList
> {
> public string MyValue1 = "alert('Hey there!');";
> public string MyValue2 = "alert('Hey there yourself!');";
>
> protected override DataListItem CreateItem(int itemIndex,
> ListItemType itemType)
> {
> DataListItem item = base.CreateItem(itemIndex, itemType);
>
> if (itemType == ListItemType.Item || itemType ==
> ListItemType.AlternatingItem)
> {
> item.Attributes.Add("onmouseover", MyValue1);
> item.Attributes.Add("onmouseout", MyValue2);
> }
>
> return item;
> }
> }
>
> Pretty simple right? Well, when I put MyDataList on the page and
> DataBind() my items to it, the attributes are NOWHERE to be seen. The
> items and their values show up great, just not my attributes.
>
> Anyone have any thoughts?
>
> Thanx!
>
> J'son
>