开发者

binding random XmlDataSource to a repeater with Xpath

开发者 https://www.devze.com 2023-02-05 02:31 出处:网络
I\'m creating page to put together a list of cinema trailers on an asp.net web page inside of a repeater.

I'm creating page to put together a list of cinema trailers on an asp.net web page inside of a repeater.

The source of the data is an online XML feed.

To do this I'm binding the repeater as follows...

string XML_FEED_URL = "http://some-cinema-feed.com/comingsoon/";

XmlDataSource data_source = new XmlDataSource();
data_source.DataFile = XML_FEED_URL;
data_source.XPath = "/movies/movie[position() > 0 and position() < 3]";

this.moviePreciewsRepeater.DataSource = data_source;
this.movieP开发者_StackOverflow中文版reciewsRepeater.DataBind();

The issue is that the length of the feed changes regularly and rather than selecting a range of movies with the XPATH (i.e. 1-3 in the XML) I need to select 3 totally random movies from the XML and bind this back to the repeater.


Use:

data_source.XPath = 
    string.Format(@"/movies/movie[position() = {0} 
                               or position() = {1}
                               or position() = {2}
                                 ]",
                  random1, random2, random3); 

where the variables random1, random2 and random3 are the random integers you have already calculated.

0

精彩评论

暂无评论...
验证码 换一张
取 消