我正在构建一个调查应用程序。我有一个页面,可以让管理员、客户、测量员和其他经理查看针对/为他们安排的调查。它还显示其状态和其他内容。我在 gridview 操作列中有 3 个图像按钮。我在运行时将一些样式和 Javascript 函数绑定到它们。这是事件代码:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int clientID = int.Parse(((System.Data.DataRowView)(e.Row.DataItem)).Row.ItemArray[5].ToString());
int surveyID = int.Parse(((System.Data.DataRowView)(e.Row.DataItem)).Row.ItemArray[6].ToString());
int scheduleID = int.Parse(((System.Data.DataRowView)(e.Row.DataItem)).Row.ItemArray[0].ToString());
//string latitude = ((System.Data.DataRowView)(e.Row.DataItem)).Row.ItemArray[12].ToString();
//string longitude = ((System.Data.DataRowView)(e.Row.DataItem)).Row.ItemArray[13].ToString();
//string address = ((System.Data.DataRowView)(e.Row.DataItem)).Row.ItemArray[14].ToString();
string status = ((System.Data.DataRowView)(e.Row.DataItem)).Row.ItemArray[1].ToString();
//hdnMapCoordinates.Value += latitude + "|" + longitude + "|" + address + "|" + status + "~";
List<int> cellsList = new List<int>(new int[] { 0, 1, 2, 3, 4, 5, 6, 7 });
for (int i = 0; i < cellsList.Count; i++)
{
e.Row.Cells[cellsList[i]].Style.Add("cursor", "pointer");
e.Row.Cells[cellsList[i]].CssClass = "inline";
e.Row.Cells[cellsList[i]].Attributes.Add("href", "#inline_content3");
e.Row.Cells[cellsList[i]].Attributes.Add("onclick", string.Format("OpenForm({0},{1},{2},'{3}'); return false;", surveyID, clientID, scheduleID, status));
}
System.Web.UI.WebControls.Image imgStatus = (System.Web.UI.WebControls.Image)e.Row.FindControl("imgStatus");
((ImageButton)e.Row.FindControl("imgOpenSurvey")).OnClientClick = string.Format("OpenSurvey({0} , {1} , {2});return false;", surveyID, clientID, scheduleID);
((ImageButton)e.Row.FindControl("imgApprove")).OnClientClick = string.Format("ApproveSurvey({0});return false;", scheduleID);
if (userRole.Contains("Supervisor"))
{
if (status == "submitted")
{
((ImageButton)e.Row.FindControl("imgApprove")).Visible = true;
}
}
((ImageButton)e.Row.FindControl("imgOpenSurvey")).Style.Add("display", "none");
if (status == "new" || status == "NEW" || status == "scheduled")
{
imgStatus.ImageUrl = "~\\Images\\new.png";
imgStatus.ToolTip = "new";
}
else if (status == "submitted")
{
imgStatus.ImageUrl = "~\\Images\\approve-required.png";
imgStatus.ToolTip = "submitted";
}
else if (status == "approved")
{
((ImageButton)e.Row.FindControl("imgOpenSurvey")).Style.Add("display", "");
((ImageButton)e.Row.FindControl("imgPrintSurvey")).Style.Add("display", "");
imgStatus.ImageUrl = "~\\Images\\checkmark.png";
imgStatus.ToolTip = "approved";
}
else if (status == "seen")
{
((ImageButton)e.Row.FindControl("imgOpenSurvey")).Style.Add("display", "");
((ImageButton)e.Row.FindControl("imgPrintSurvey")).Style.Add("display", "");
imgStatus.ImageUrl = "~\\Images\\checkmark.png";
imgStatus.ToolTip = "approved";
//e.Row.BackColor = Color.FromArgb(153, 255, 153);
}
else if (status == "on-hold")
{
imgStatus.ImageUrl = "~\\Images\\close-btn.png";
imgStatus.ToolTip = "On-Hold";
}
else if(status == "canceled"){
imgStatus.ImageUrl = "~\\Images\\cancel.png";
imgStatus.ToolTip = "Canceled";
}
}
}
现在的问题是当我对这个页面运行 ANTS Performance Profiler 7.1 并发现这个事件被点击了 297 次。加载页面花费的时间最多。现在我需要任何替代方法或一些改进页面性能的技巧。分页和其他事情已经尝试过了。谢谢你。