我想通过计时器自动刷新gridview。 (我希望它像实时数据一样工作)
它无法正常工作。没有错误,但gridview不会自动刷新。
如何使用计时器或其他方式刷新网格视图,如实时数据?
Aspx
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<dx:ASPxTimer runat="server" ID="tm" OnTick="tm_Tick">
</dx:ASPxTimer>
<dx:ASPxGridView.........
........
</dx:ASPxGridView>
</ContentTemplate>
</asp:UpdatePanel>
C#
protected void Page_Load(object sender, EventArgs e)
{
String strConnString =
ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "MainStrdPrc";
cmd.Connection = con;
try
{
con.Open();
grdDealerList.DataSource = cmd.ExecuteReader();
grdDealerList.DataBind();
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
con.Dispose();
}
grdDealerList.EnableCallBacks = true;
tm.Interval = 5000;
}
protected void tm_Tick(object sender, EventArgs e)
{
grdDealerList.DataBind();
}
答案 0 :(得分:0)
我想问题是计时器没有启动。
您是否可以尝试添加tm.Start()
并将网格绑定到pageload中的非回发部分?