ASP.net直放站 - N设置重复次数最多? [英] ASP.net Repeater -- setting N Maximum Repetitions?

查看:111
本文介绍了ASP.net直放站 - N设置重复次数最多?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是Repeater控件现在上显示来自多个不同的网站SQL Server数据。我想知道,如果有任何方式的做一个中继器只有重复或通过其运行周期最多N次。

I am using a Repeater control to display data from a SQL server on multiple different sites right now. I am wondering if there is any way to make a repeater only "repeat" or run through its cycles a maximum of N times.

我拆了一个div元素融入其中4只是有足够的空间容纳该转发器的4个周期相等的部分。如果它运行的4倍以上,这一切都推下来div和图像开始/文我会preFER避免新行。它使网页看起来丑陋并没有真正大有作为的客户端。

I split a Div element up into 4 equal sections which have just enough room for 4 cycles of this repeater. If it runs more than 4 times, it pushes everything down in the div and begins a new row of images/text I would prefer to avoid. It makes the web page look uglier and does not really accomplish much for the client.

另外,有没有办法为随机选择它通过中继器循环上得到显示?例如,有一次页面加载,中继器重复拉2-5,那么刷新页面,中继拉迭代1-4。这将是非常酷的,如果我能有这样的出现是随机的图像/文本。

Also is there any way to randomly select which iterations through the repeater get displayed? For example, one time the page loads, the repeater pulls iterations 2-5, then you refresh the page and the repeater pulls iterations 1-4. That would be very cool if I could make the images/text that show up to be random.

对于那些很好奇,一个转发器是一个ASP.net对象基本上反复显示或以其他方式从表中,SQL数据库等数据打交道它只是由行到任何的数据去行。

For those that are curious, a repeater is an ASP.net object which basically iteratively displays or otherwise works with data from a table, SQL database, etc. It just goes row by row through whatever the data is.

推荐答案

而不是试图做任何时髦与中继器,你可以将它绑定到你的中继之前,这样做是为了您的数据源本身。

Rather than try to do anything funky with the repeater, you can do this to your data source itself before binding it to your repeater.

例如:

var rand = new Random();
var myCollection = GetSomethingFromSomewhere();
myRepeater.DataSource = myCollection
    .OrderBy(x => rand.Next())
    .Take(4);
myRepeater.DataBind();

这篇关于ASP.net直放站 - N设置重复次数最多?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆