定时刷新DataGrid
我用AjaxPro,后台代码
[AjaxPro.AjaxMethod]
private string ShowData()
{
string sql= "select * from "+TableName+(sefileid!=0? " where SEFile_ID= "+sefileid: " ");
DataTable dt=db.OpenTable(sql);
dgData.DataSource=dt;
dgData.DataBind();
System.Text.StringBuilder sb=new System.Text.StringBuilder();
System.IO.StringWriter sw=new System.IO.StringWriter(sb);
System.Web.UI.HtmlTextWriter htw=new HtmlTextWriter(sw);
dgData.RenderControl(htw);
string s=sb.ToString();
return s;
前台代码
function Call_Show()
{
var cc=document.getElementById( "dgData ");
cc.innerHTML=SEFile.ShowData().value;
}
function Call_Server()
{
SEFile_ShowData();
Call_Show();
}
我怎么定时刷新DataGrid??
我用window.onload=setInterval( "Call_Server() ",1000);
setTimtOut都不行 提示网页有错误??
该怎么解决
------解决方案--------------------我来顶一下
------解决方案--------------------我也是看ajax实战,看完后有段时间没用ajaxpro了,你的前台代码cc.innerHTML=SEFile.ShowData().value;我记得ajaxpro不是这样掉用吧,SEFile.ShowData(Call_Show_callback);然后再写一个Call_Show_callback(res){cc.innerHTML=res.value;},还有,以前用的时候听人说ajaxpro中类似于cc.innerHTML=SEFile.ShowData()这样的调用不是真正的异步,听说而已。提示未定义你是否注册了SEFile,同时好像在2003中要写成 你的项目名.SEFile.ShowData ,说错务怪啊
------解决方案--------------------类代码:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace MyAJAX
{
/// <summary>
///
/// </summary>
public partial class Test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(MyAJAX.Test));
}
[AjaxPro.AjaxMethod()]
public void GetSubCategory(int iCategoryID)
{
Random rand = new Random();
SqlConnection conn = null;
try
{
conn = new SqlConnection( "Data Source=(local); User ID=sa;Password=hztsa; Initial Catalog=test ");
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = string.Format( "Update Video Set DownLoadCount = DownLoadCount + 1 ");
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
string str = ex.Message;
}
finally
{
if (conn != null && conn.State != ConnectionState.Closed)
{
conn.Close();
}
}
string[] testStr = new string[10000];
for (int i = 0; i < testStr.Length; i++)
{
testStr[i] = "fdd ";
}
// System.Threading.Thread.Sleep(500 + rand.Next(1000));
}
}