DataPager控件自动改变页面每隔5秒 [英] Datapager control changing pages automatically every 5 seconds
问题描述
我必须连接到SQL数据库ListView控件,我成立了一个DataPager的限制每个页面(占3页)上显示的项目。
I have a listview control connected to an SQL database, I have set up a datapager to limit the items shown on each page (3 per page).
我已经DataPager的设置为:可见=假,想知道如何使DataPager的变化自动页面每隔5秒
I have set the datapager to: visible=false and would like to know how to make the datapager change pages automatically every 5 seconds.
在此先感谢给予任何帮助。
Thanks in advance for any help given.
推荐答案
我有同样的问题和解决的方法很简单。
I had the same problem and the solution is very simple.
第一步是包括DataPager控件和网页上的定时器控制。
The first step is to include a DataPager control and a Timer control on your page.
<asp:DataPager ID="pager" runat="server" PagedControlID="listView" PageSize="10">
<Fields>
<asp:NumericPagerField ButtonType="Link" />
</Fields>
</asp:DataPager>
<asp:Timer ID="timer" runat="server" Interval="1000" OnTick="timer_Tick">
</asp:Timer>
接下来,你必须写这篇code:
Next, you must be write this code:
protected void timer_Tick(object sender, EventArgs e) {
//Verify that the session variable is not null
if (Session["startRowIndex"] == null)
Session.Add("startRowIndex", 0);
//Create a variable to store the first record to show
int startRowIndex = Convert.ToInt32(Session["startRowIndex"]);
//Show from the first record to the size of the page
this.pager.SetPageProperties(startRowIndex, this.pager.MaximumRows, true);
//Increase the first record to display in the size of the page
startRowIndex += this.pager.MaximumRows;
//If the first record exceeds the total number of records, restart the count.
if (startRowIndex > this.pager.TotalRowCount) startRowIndex = 0;
Session["startRowIndex"] = startRowIndex;
}
,并把这个code在Page_Load事件:
And put this code in the Page_Load event:
protected void Page_Load(object sender, EventArgs e) {
//This session variable to control the record to show for each tick
if (!IsPostBack) Session.Add("startRowIndex", 0);
}
我希望你成为的东西,如果它不是太迟了,对不起我的英语水平,因为它不是我的母语。
I hope you serve something, if it's not too late, and sorry for my English, because it is not my native language.
问候来自智利。
这篇关于DataPager控件自动改变页面每隔5秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!