I am building a survey application. I have a page which gives Admin, Clients, Surveyor and other managers a view of surveys scheduled against/for them. It also displays its status and other things. I have 3 image buttons in a gridview Action column. I am on run time binding some styles and Javascript functions to them. This is the event code:
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";
}
}
}
Now issue is when I ran ANTS Performance Profiler 7.1 against this page and found that this event is hit 297 times. Which is taking most time to load a page. Now I need any alternative to this or some tips for improvement in page's performance. Paging and other things have already been tried. Thank you.