我试图根据线程的状态更改asp.net中的网格视图表的背景色,该线程启动事件,从该事件中启动以下程序(已调试并确保已被调用):< / p>
protected void updateGridView(UpdateGridViewArgs e)
{
if (e.Status == "Complete")
{
this.dgv_Display.Rows[e.Index].BackColor = Color.Green;
this.dgv_Display.Rows[e.Index].ForeColor = Color.Yellow;
}
else if (e.Status == "Error")
{
this.dgv_Display.Rows[e.Index].BackColor = Color.Red;
this.dgv_Display.Rows[e.Index].ForeColor = Color.Yellow;
}
else if (e.Status == "Ongoing")
{
this.dgv_Display.Rows[e.Index].BackColor = Color.Yellow;
this.dgv_Display.Rows[e.Index].ForeColor = Color.Black;
if (e.Index > 5)
{
//DisplayJobs.Invoke(new Action(() => DisplayJobs.FirstDisplayedScrollingRowIndex = Index - 5));
}
}
}
但是,gridview表不会更改。
启动时
this.dgv_Display.Rows[0].BackColor = Color.Green;
在按钮单击事件中,该行会更改颜色,请告知。
事件触发脚本:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace CustomEvents
{
public delegate void UpdateGridViewHandler(UpdateGridViewArgs e);
public class UpdateGridViewArgs : EventArgs
{
public string Status;
public int Index;
public UpdateGridViewArgs(string status, int index)
{
this.Status = status;
this.Index = index;
}
}
}
调用触发器:
FleetMonitor.UpdateDataTable(new UpdateGridViewArgs("Ongoing", index));
触发事件处理设置:
public static event UpdateGridViewHandler _gridViewEventHandler;
protected void Page_Load(object sender, EventArgs e)
{
ConfigFile.Initialize("C:/IIS/App_Data/FleetMonitor.config");
Limits.Initialize();
populateGridView();
populate_cmb_Times();
_gridViewEventHandler += new UpdateGridViewHandler(updateGridView);
}
public static void UpdateDataTable(UpdateGridViewArgs e)
{
if (_gridViewEventHandler != null)
{
_gridViewEventHandler(e);
}
}
触发事件处理:
protected void updateGridView(UpdateGridViewArgs e)
{
if (e.Status == "Complete")
{
this.dgv_Display.Rows[e.Index].BackColor = Color.Green;
this.dgv_Display.Rows[e.Index].ForeColor = Color.Yellow;
}
else if (e.Status == "Error")
{
this.dgv_Display.Rows[e.Index].BackColor = Color.Red;
this.dgv_Display.Rows[e.Index].ForeColor = Color.Yellow;
}
else if (e.Status == "Ongoing")
{
this.dgv_Display.Rows[e.Index].BackColor = Color.Yellow;
this.dgv_Display.Rows[e.Index].ForeColor = Color.Black;
this.dgv_Display.UpdateRow(e.Index, false);
if (e.Index > 5)
{
//DisplayJobs.Invoke(new Action(() => DisplayJobs.FirstDisplayedScrollingRowIndex = Index - 5));
}
}
}