嗨,是否可以在一个时间间隔内触发gridindex更改gridview的事件?
实际上我尝试了一些代码,但它显示的页面事件不存在。如何在asp.net c#application中的计时器时间点调用此事件?
谢谢
答案 0 :(得分:2)
ASPX标记
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server"
AllowPaging="True" PageSize="3">
</asp:GridView>
<asp:Timer ID="Timer1" runat="server" Interval="2000" ontick="Timer1_Tick1">
</asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
</form>
代码隐藏
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Data();
}
}
void Data()
{
DataTable dt = new DataTable();
dt.Columns.Add("No");
for (int i = 1; i <= 13; i++)
{
dt.Rows.Add(i.ToString());
}
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void Timer1_Tick1(object sender, EventArgs e)
{
if (GridView1.PageCount == GridView1.PageIndex)
Timer1.Enabled = false;
GridView1.PageIndex++;
Data();
}