GridView RowDataBound事件降低了应用程序ASP.NET C#的速度
GridView RowDataBound event slowing down application ASP.NET C#
我正在构建一个调查应用程序。我有一个页面,可以让管理员、客户、测量师和其他经理查看针对他们/为他们安排的调查。它还显示其状态和其他内容。我在一个gridview Action列中有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次。加载页面需要花费大部分时间。现在,我需要任何替代方案,或者一些改进页面性能的技巧。寻呼和其他事情已经尝试过了。非常感谢。
您尝试过自定义分页吗?默认的网格视图分页只是客户端。
这取决于你的网格视图中有多少条记录。如果您通过数据源获取所有记录,则附加的格式化&转换肯定会降低应用程序的速度。在这种情况下,自定义数据库分页总是首选的,所以您只需要从数据库中获取每页10条记录&仅对这些应用格式设置。
SELECT ...
FROM
(SELECT ...
ROW_NUMBER() OVER(ORDER BY ColumnName) as RowNum
FROM Employees e
) as DerivedTableName
WHERE RowNum BETWEEN @startRowIndex AND (@startRowIndex + @maximumRows) - 1
在这里,您可以传递页面的startRowIndex(gridview会自动传递),即每页要获取的最大行数(gridview也可以这样做)。
这将需要一些时间来设置,但结果是值得的。请阅读这篇文章在ASP.NET中自定义分页4家伙从rolla
相关文章:
- 借助asp.net验证或java脚本对多个文本进行验证
- 将Javascript数组发送到控制器ASP.NET MVC
- ASP.NET通过单击JavaScript按钮触发c#事件
- 文本框不是从Javascript/Asp.net中的对话框中打印出来的
- 从javascript调用asp.net codebehind函数
- 使用javascript的Asp.net内容占位符
- 获取ASP.NET Ajax Timer状态
- ASP.NET网络摄像头显示
- 如何在只能有一个asp.net表单的主页上从asp.net页面中的javascript中获取值
- 如何将乳胶配方奶粉图像保存到Asp.net中的文件夹中
- asp.net,包括iss上的javascript slow
- 选择不在GridView-ASP.NET中激发
- 什么'是在asp.net MVC中将本地化的resources.resx文件转换为javascript文件的有效
- 使用ASP.NET将谷歌地图添加到项目中,并从数据库中检索位置
- 有什么“;错误的”;将javascript放在asp.net表单上,而不是放在单独的文件中
- 将Javascript日期转换为ASP.NET日期格式
- C#asp.net mvc Set CheckBoxFor已检查的具有Model Value的属性
- 如何使用javascript vb.net asp.net关闭web表单
- 在Ext.net (ASP.NET)中上传完成事件
- 以编程方式滚动/移动到.net asp:listview控件中的一个项目