Problem adding attributes to DataListItem..

Discussion in 'ASP .Net Web Controls' started by J'son, Dec 12, 2005.

  1. J'son

    J'son Guest

    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
     
    J'son, Dec 12, 2005
    #1
    1. Advertising

  2. J'son,

    I think instead of adding the attributes in the overriden function you
    should try adding the attributes after the items have been created by using
    the OnItemDatabound event. I have successfully added attributes within the
    event.

    --
    Sincerely,

    S. Justin Gengo, MCP
    Web Developer / Programmer

    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzsche
    "J'son" <> wrote in message
    news:...
    > 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
    >
     
    S. Justin Gengo, Dec 12, 2005
    #2
    1. Advertising

  3. J'son

    Guest

    Justin,

    I can add attributes via the web page in just about any of the "OnItem"
    events for the DataList. What I would like to do is to create a
    reusable DataList control that would add the attributes with preset
    values ready to go. That way I could do something like this:

    <cc1:MyDataList id="MyDataList1" runat="server"
    MouseOverItemValue="some value" MouseOutItemValue="someother value">

    It seems pretty straightforward but I must be missing something..

    Thanx

    J'son
     
    , Dec 12, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mathew Quick
    Replies:
    1
    Views:
    312
    John Saunders
    Jun 15, 2004
  2. Phil Corrin
    Replies:
    1
    Views:
    2,194
  3. J'son
    Replies:
    3
    Views:
    1,486
    =?Utf-8?B?YXNhcGppbQ==?=
    Mar 2, 2006
  4. J'son

    Problem adding attributes to DataListItem..

    J'son, Dec 12, 2005, in forum: ASP .Net Building Controls
    Replies:
    3
    Views:
    121
    asapjim
    Mar 2, 2006
  5. Brian Paul

    DataListItem in DataList does not render attributes/Tooltips

    Brian Paul, Jan 15, 2004, in forum: ASP .Net Web Controls
    Replies:
    5
    Views:
    478
    Julience
    Mar 2, 2004
Loading...

Share This Page