我在 Default.aspx.cs 中的自动刷新代码:
protected void Page_Load(object sender, EventArgs e)
{
// Auto refresh every 5 second
Response.AppendHeader("Refresh",5+"; URL=Default.aspx");
// Auto update into database
con = new MySqlConnection(conStr);
con.Open();
cmd = new MySql.Data.MySqlClient.MySqlCommand();
cmd.Connection = con;
con = new MySql.Data.MySqlClient.MySqlConnection(conStr);
GridView1.DataSourceID = "Datacmd";
// Get status of process on server of pid(cells[6])
count = GridView1.Rows.Count;
string server = "";
string pid = "";
string status = "";
string cout = GridView1.Rows.count;
for (int i = 0; i < count; i++)
{
server = GridView1.Rows[i].Cells[1].Text;
switch (server)
{
// If server locahost
case "localhost":
pid = GridView1.Rows[i].Cells[6].Text;
status = ws.GetStatusProcess(pid); //Ws is My webservice have a function GetStatusProcess(string pid)
string SQL = "UPDATE command SET status='" + status + "' WHERE id=" + int.Parse(GridView1.Rows[i].Cells[0].Text) + "";
cmd.CommandText = SQL;
cmd.ExecuteNonQuery();
con.Close();
GridView1.DataSourceID = "Datacmd";
break;
// case : etc...
default:
break;
}
}
}
自动更新到数据库工作正常。
但是,当我单击 Gridview1 上的按钮编辑 (ShowEditButton="True") 时,我无法在 Gridview1 上编辑行。因为页面会自动刷新。
如何使自动刷新页面停止在 Gridview 编辑模式下工作?