Accessing DataItem in Rotator

3 posts, 1 answers
  1. Viktor Takacs
    Viktor Takacs avatar
    95 posts
    Member since:
    Mar 2006

    Posted 14 Jul 2011 Link to this post

    Hi,
    I am trying to manipulate some controls of a RotatorItem in the ItemDataBound event. However, the e.Item.DataItem seems to be of type XmlDataSourceNodeDescriptor, with which I can't do much since it's a sealed class. I can see all my data there while debugging, but cannot access them. Any idea how? Fo example, I have a simple xml file like this:
    <Images>
      <Image>
        <ImageUrl>PICT3345.jpg</ImageUrl>
      </Image>
      <Image>
        <ImageUrl>PICT4357.jpg</ImageUrl>
      </Image>
      <Image>
        <ImageUrl>PICT4479.jpg</ImageUrl>
      </Image>
      <Image>
        <ImageUrl>PICT5344.jpg</ImageUrl>
      </Image>
      <Image>
        <ImageUrl>PICT6294.jpg</ImageUrl>
      </Image>
      <Image>
        <ImageUrl>PICT6356.jpg</ImageUrl>
      </Image>
      <Image>
        <ImageUrl>PICT6898.jpg</ImageUrl>
      </Image>
      <Image>
        <ImageUrl>PICT7276.jpg</ImageUrl>
      </Image>
    </Images>

    (Obviously) I want to get to the InnerText of ImageUrl but I cannot.

    Any help is greatly appreciated!

    viktor



  2. Answer
    Niko
    Admin
    Niko avatar
    387 posts

    Posted 14 Jul 2011 Link to this post

    Hi Viktor,

    Indeed, you are not supposed to be able to use the DataItem directly. Rather you should use the corresponding DataBinder class with its static Eval method. In your case this will be the XPathBinder. Here is the sample code to capture the text of the ImageUrl element:
    var imageUrl = XPathBinder.Eval(e.Item.DataItem, "ImageUrl");

    Hope this helps.

    Greetings,
    Niko
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Viktor Takacs
    Viktor Takacs avatar
    95 posts
    Member since:
    Mar 2006

    Posted 14 Jul 2011 Link to this post

    Yes, that's right, thank you for the quick reply! I never would have guessed myself...

    thanks, Niko!
Back to Top