This is a migrated thread and some comments may be shown as answers.

Accessing DataItem in Rotator

2 Answers 52 Views
Rotator
This is a migrated thread and some comments may be shown as answers.
Viktor Takacs
Top achievements
Rank 2
Viktor Takacs asked on 14 Jul 2011, 09:55 AM
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 Answers, 1 is accepted

Sort by
0
Accepted
Niko
Telerik team
answered on 14 Jul 2011, 04:14 PM
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!

0
Viktor Takacs
Top achievements
Rank 2
answered on 14 Jul 2011, 04:35 PM
Yes, that's right, thank you for the quick reply! I never would have guessed myself...

thanks, Niko!
Tags
Rotator
Asked by
Viktor Takacs
Top achievements
Rank 2
Answers by
Niko
Telerik team
Viktor Takacs
Top achievements
Rank 2
Share this question
or