以时间间隔显示值 [英] display values in interval of time
本文介绍了以时间间隔显示值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在标签中显示一组值{20,21,22,23,24,25,26,27,28,29,30}。
我使用了计时器及其工作正常,
但问题是页面重新加载。
没有重新加载页面如何使它成为可能。
我的代码是:
.aspx页面:
I want to display set of values{20,21,22,23,24,25,26,27,28,29,30} in a label.
I used timer and its working fine,
But the issue is the page getting reloaded.
without reloading the page how to make it possible.
My Code is:
.aspx page:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<div style="height: 100px; width: 100px; background-color: LightSkyBlue; border-radius: 3px;">
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</div>
</div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Timer ID="Timer1" runat="server" Interval="2000" OnTick="Timer1_Tick">
</asp:Timer>
</form>
</body>
</html>
代码背后:
Code behind:
public void user_online()
{
Timer1.Interval = 2000;
}
protected void Timer1_Tick(object sender, EventArgs e)
{
string conn = ConfigurationManager.ConnectionStrings["connection_name"].ToString();
SqlConnection con = new SqlConnection(conn);
if (con.State == ConnectionState.Closed)
{
con.Open();
}
string q = "select top 1 * from temp_no order by newid()";
SqlCommand cmd = new SqlCommand(q, con);
SqlDataReader dr = cmd.ExecuteReader();
dr.Read();
Label1.Text = dr["student_online"].ToString();
if (con.State == ConnectionState.Open)
{
con.Close();
con.Dispose();
}
}
推荐答案
尝试使用 UpdatePanel [ ^ ]。
UpdatePanel控件概述 [ ^ ]
Try using an UpdatePanel[^].
UpdatePanel Control Overview[^]
这篇关于以时间间隔显示值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文