【发布时间】:2011-08-10 13:46:07
【问题描述】:
我有一个连接到 SQL 数据库的 listview 控件,我设置了一个数据分页器来限制每个页面上显示的项目(每页 3 个)。
我已将 datapager 设置为:visible=false,并想知道如何使 datapager 每 5 秒自动换页。
提前感谢您提供的任何帮助。
【问题讨论】:
-
您需要使用timer control 或深入研究一些Javascript
我有一个连接到 SQL 数据库的 listview 控件,我设置了一个数据分页器来限制每个页面上显示的项目(每页 3 个)。
我已将 datapager 设置为:visible=false,并想知道如何使 datapager 每 5 秒自动换页。
提前感谢您提供的任何帮助。
【问题讨论】:
我遇到了同样的问题,解决方法很简单。
第一步是在页面上包含一个 DataPager 控件和一个 Timer 控件。
<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>
接下来,你必须编写这段代码:
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;
}
并将这段代码放在 Page_Load 事件中:
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);
}
我希望你能提供一些东西,如果不是太晚的话,对不起我的英语,因为它不是我的母语。
来自智利的问候。
【讨论】: