This is a migrated thread and some comments may be shown as answers.

need to improve the perfomance of radgrid

1 Answer 111 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Shimab
Top achievements
Rank 1
Shimab asked on 03 Nov 2011, 08:34 AM

 

We are using radgrid with lot of controls within radgrid. Please find the code aspx code for this radgrid controls
  
<asp:RadGrid ID="grdTimesheet" runat="server" GridLines="Both" OnNeedDataSource="grdTimesheet_NeedDataSource"
OnItemDataBound="grdTimesheet_ItemDataBound" OnPreRender="grdTimesheet_PreRender"
OnItemCommand="grdTimesheet_ItemCommand" ClientSettings-AllowColumnsReorder="true"
ShowFooter="true" ShowHeader="true">
<MasterTableView EditMode="InPlace" CommandItemDisplay="Top" AutoGenerateColumns="false">
<Columns>
<telerik:GridCheckBoxColumn HeaderText="<%$ Resources:Culture, grdTimesheethdrSubmit %>"
UniqueName="IsSubmitted" DataField="IsSubmitted" ReadOnly="true" HeaderStyle-HorizontalAlign="Center"
ItemStyle-HorizontalAlign="center" FooterStyle-HorizontalAlign="Center" FooterStyle-Font-Bold="true"
FooterStyle-VerticalAlign="Middle" HeaderStyle-Width="70px" ItemStyle-BackColor="#F5F5F5" />
<telerik:GridTemplateColumn UniqueName="Site" HeaderText="<%$ Resources:Culture, grdTimesheethdrSite %>"
DataField="Site_Key" ItemStyle-HorizontalAlign="center" HeaderStyle-Width="70px"
HeaderStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:TextBox Text='<%#DataBinder.Eval(Container.DataItem,"SiteFormattedID") %>' runat="server"
Style="width: 68px;" />
<table id="cmbSite" runat="server" border="0" cellpadding="0" cellspacing="0" style="width: 100%;
height: 100%">
<tr>
<td>
<asp:TextBox class="input" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"SiteFormattedID") %>' />
</td>
<td>
<asp:Image ID="btnImg" runat="server" Height="17px" Width="20px" ImageUrl="~/Images/ellipse.png" />
</td>
</tr>
</table>
<asp:HiddenField ID="hdnSitetext" runat="server" Value='<%#DataBinder.Eval(Container.DataItem,"SiteFormattedID") %>' />
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn UniqueName="ProfCtr" HeaderText="<%$ Resources:Culture, grdTimesheethdrProfCenter %>"
DataField="Profit_Center_Key" ItemStyle-HorizontalAlign="center" HeaderStyle-Width="90px"
HeaderStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:TextBox Text='<%#DataBinder.Eval(Container.DataItem,"Profit_Center_Key") %>'
runat="server" />
<telerik:RadComboBox runat="server" ID="cmbProfCtr" ShowToggleImage="true" Width="100%"
DropDownWidth="100px" OnClientSelectedIndexChanged="showSelected" OnClientDropDownClosed="OnClientDropDownClosedHandler"
OnClientBlur="OnClientBlur" MarkFirstMatch="true" />
<asp:HiddenField ID="hdnProfCtr" Value='<%#DataBinder.Eval(Container.DataItem,"Profit_Center_Key") %>'
runat="server" />
<asp:HiddenField ID="hdnProfCtrtext" Value='' runat="server" />
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn UniqueName="WorkType" HeaderText="<%$ Resources:Culture, grdTimesheethdrWrkType %>"
HeaderStyle-Width="77px" ItemStyle-Height="25px" HeaderStyle-HorizontalAlign="Center"
ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:TextBox Text='<%#DataBinder.Eval(Container.DataItem,"WorkType_Name") %>' runat="server" />
<telerik:RadComboBox runat="server" ID="cmbWorkType" ShowToggleImage="true" Width="100%"
DropDownWidth="200px" OnClientSelectedIndexChanged="itemText" OnClientDropDownClosed="OnClientDropDownClosedHandler"
OnClientBlur="OnClientBlur" MarkFirstMatch="true" />
<asp:HiddenField ID="hdnWorkType" Value='<%#DataBinder.Eval(Container.DataItem,"WorkType_KeyAndCategory") %>'
runat="server" />
<asp:HiddenField ID="hdnWorkTypetext" Value='' runat="server" />
<asp:HiddenField ID="hdnWorkTypeCode" Value='<%#DataBinder.Eval(Container.DataItem,"WorkType_Name") %>'
runat="server" />
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn UniqueName="Category" HeaderText="<%$ Resources:Culture, grdTimesheethdrCategory %>"
DataField="WorkType_Category" ItemStyle-HorizontalAlign="center" HeaderStyle-HorizontalAlign="Center"
ItemStyle-VerticalAlign="Middle" FooterStyle-Font-Bold="true" FooterStyle-HorizontalAlign="Center"
FooterStyle-VerticalAlign="Middle" HeaderStyle-Width="70px" ReadOnly="true" ItemStyle-BackColor="#F5F5F5"
ItemStyle-ForeColor="Black">
</telerik:GridBoundColumn>
<telerik:GridCheckBoxColumn HeaderText="<%$ Resources:Culture, grdTimesheethdrTimecard %>"
UniqueName="IsTimeCard" DataField="IsTimeCardEntry" ReadOnly="true" HeaderStyle-HorizontalAlign="Center"
ItemStyle-HorizontalAlign="center" FooterStyle-HorizontalAlign="Center" FooterStyle-Font-Bold="true"
FooterStyle-VerticalAlign="Middle" HeaderStyle-Width="70px" ItemStyle-BackColor="#F5F5F5" />
<telerik:GridBoundColumn HeaderText="Day1" UniqueName="Day1" DataField="Day1" HeaderStyle-HorizontalAlign="Center"
HeaderStyle-Width="73px" FooterStyle-HorizontalAlign="Center" FooterStyle-Font-Bold="true"
FooterStyle-VerticalAlign="Middle" />
<telerik:GridBoundColumn HeaderText="Day2" UniqueName="Day2" DataField="Day2" HeaderStyle-HorizontalAlign="Center"
HeaderStyle-Width="73px" FooterStyle-HorizontalAlign="Center" FooterStyle-Font-Bold="true"
FooterStyle-VerticalAlign="Middle" />
<telerik:GridBoundColumn HeaderText="Day3" UniqueName="Day3" DataField="Day3" HeaderStyle-HorizontalAlign="Center"
HeaderStyle-Width="73px" FooterStyle-HorizontalAlign="Center" FooterStyle-Font-Bold="true"
FooterStyle-VerticalAlign="Middle" />
<telerik:GridBoundColumn HeaderText="Day4" UniqueName="Day4" DataField="Day4" HeaderStyle-HorizontalAlign="Center"
HeaderStyle-Width="73px" FooterStyle-HorizontalAlign="Center" FooterStyle-Font-Bold="true"
FooterStyle-VerticalAlign="Middle" />
<telerik:GridBoundColumn HeaderText="Day5" UniqueName="Day5" DataField="Day5" HeaderStyle-HorizontalAlign="Center"
HeaderStyle-Width="73px" FooterStyle-HorizontalAlign="Center" FooterStyle-Font-Bold="true"
FooterStyle-VerticalAlign="Middle" />
<telerik:GridBoundColumn HeaderText="Day6" UniqueName="Day6" DataField="Day6" HeaderStyle-HorizontalAlign="Center"
HeaderStyle-Width="73px" FooterStyle-HorizontalAlign="Center" FooterStyle-Font-Bold="true"
FooterStyle-VerticalAlign="Middle" />
<telerik:GridBoundColumn HeaderText="Day7" UniqueName="Day7" DataField="Day7" HeaderStyle-HorizontalAlign="Center"
HeaderStyle-Width="73px" FooterStyle-HorizontalAlign="Center" FooterStyle-Font-Bold="true"
FooterStyle-VerticalAlign="Middle" />
<telerik:GridBoundColumn HeaderText="<%$ Resources:Culture, grdTimesheethdrTotal %>"
UniqueName="Total" DataField="Total" ReadOnly="true" ItemStyle-HorizontalAlign="center"
HeaderStyle-HorizontalAlign="Center" FooterStyle-Font-Bold="true" FooterStyle-HorizontalAlign="Center"
FooterStyle-VerticalAlign="Middle" HeaderStyle-Width="55px" ItemStyle-BackColor="#F5F5F5"
ItemStyle-ForeColor="Black" />
<telerik:GridTemplateColumn HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center"
UniqueName="Delete" ItemStyle-BackColor="#F5F5F5" HeaderStyle-Width="15px">
<ItemTemplate>
<asp:LinkButton ID="lnkDelete" runat="server" CommandName="DeleteSelected">
<img alt="Delete" style="border: 0px; vertical-align: middle; height: 11px; width: 11px;
text-align: center;" src="../../Images/delete.gif" />
</asp:LinkButton>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn UniqueName="RowNumber" DataField="RowNumber" ReadOnly="true"
Visible="false" />
<telerik:GridTemplateColumn UniqueName="OpenShiftDays" Visible="false">
<ItemTemplate>
<asp:HiddenField ID="hdnOpenShiftDays" runat="server" Value='<%#DataBinder.Eval(Container.DataItem,"OpenShiftDays") %>' />
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
<CommandItemTemplate>
<asp:LinkButton ID="btnAddNew" runat="server" CommandName="AddNewRow" uniquename="Add">
<asp:Button ID="btnAddNewImage" Style="border: 0px; vertical-align: middle;" runat="server"
Text="" CommandName="AddNewRow" CssClass="rgAdd" />
Add new row</asp:LinkButton>
</CommandItemTemplate>
</MasterTableView>
<HeaderStyle HorizontalAlign="Center" Font-Bold="true" CssClass="contentArea" />
<ClientSettings AllowColumnsReorder="false" ReorderColumnsOnClient="false" EnablePostBackOnRowClick="false">
<Selecting AllowRowSelect="false" />
<Scrolling AllowScroll="true" UseStaticHeaders="true" SaveScrollPosition="false"
EnableVirtualScrollPaging="false" />
<Resizing ShowRowIndicatorColumn="true" />
<ClientEvents OnRowCreated="onrowcreated" OnGridCreated="ongridcreated" />
</ClientSettings>
</asp:RadGrid>
  
  
And we have 50 to 100 or more than hundreds of records in this radgrid.
And on click of textbox we change the behaviour of other controls (on entry in textbox we need to show either dropdown or textbox).
For achiving this functionlaity we did lot of code behind code (on ItemDatabound and Onprerender) as well as javascript code.
  
Right now our functionality working fine but it would take lot of time to complete or perfomance for this controls very slow as compare to other radgrid in diffrence page.
  
  
Please find the code
  
protected void grdTimesheet_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
try
{
Hashtable hTbl = new Hashtable();
if (Session[WFConstants.TIMESHEET_PARAMS] != null)
{
hTbl = (Hashtable)Session[WFConstants.TIMESHEET_PARAMS];
}
Entities<TimesheetDetail> entTimesheetDetail = ExcelGridSource;
for (int i = 0; i < entTimesheetDetail.TotalRecords; i++)
{
grdTimesheet.EditIndexes.Add(i);
}
//check this timesheet fill from timecard or not
TimesheetDetail timecard = ((TimesheetDetail)entTimesheetDetail.Where<TimesheetDetail>(tsd => tsd.Record_Type == "Worktype" && tsd.IsTimeCardEntry == true).Take<TimesheetDetail>(1).SingleOrDefault());
if (timecard != null)
{
isTimeCardEntry = true;
}
//set the calling page to ViewType variable
GetParentPage();
//toggle visibility of submitted column[it's show only Admin view timesheet]
if (ViewType == TimesheetViewType.Administrator)
{
grdTimesheet.Columns[0].Visible = true; // show submitted column
}
else
{
grdTimesheet.Columns[0].Visible = false;
}
grdTimesheet.Columns[2].Visible = Timesheet_Is_ProfCtr; //toggle visibility of ProfitCenter column
grdTimesheet.Columns[5].Visible = isTimeCardEntry; //toggle visibility of TimeCardEntry column
#region COMMAND ITEM HANDLER
if (e.Item is GridCommandItem)
{
GridCommandItem commandItem = e.Item as GridCommandItem;
LinkButton button = commandItem.FindControl("btnAddNew") as LinkButton;
Button btnImage = commandItem.FindControl("btnAddNewImage") as Button;
//toggle disability of AddNew Row link and image based on Submit and Reopen timesheet.
if ((this.Page as PageBase).SecurityRights == enmSecurityRights.ReadOnly)
{
if (button != null && btnImage != null)
{
button.Enabled = false;
btnImage.Enabled = false;
button.Style.Add("cursor", "default");
}
else
{
button.Attributes.Remove("style");
}
}
else if (hTbl["IsNeedRecalc"] != null && hTbl["IsNeedRecalc"].ToString() != "" && Convert.ToBoolean(hTbl["IsNeedRecalc"].ToString()))
{
if (button != null && btnImage != null)
{
button.Enabled = false;
btnImage.Enabled = false;
button.Style.Add("cursor", "default");
}
else
{
button.Attributes.Remove("style");
}
}
else if (hTbl["TimesheetStatus"] != null && hTbl["TimesheetStatus"].ToString() != "" && hTbl["TimesheetStatus"].ToString() != "1")
{
if (button != null && btnImage != null)
{
button.Enabled = false;
btnImage.Enabled = false;
button.Style.Add("cursor", "default");
}
else
{
button.Attributes.Remove("style");
}
}
else if (IsTimeSheetSubmitted)
{
if (button != null && btnImage != null)
{
button.Enabled = false;
btnImage.Enabled = false;
button.Style.Add("cursor", "default");
}
else
{
button.Attributes.Remove("style");
}
}
}
#endregion
#region HEADER ITEM HANDLER
if (e.Item is GridHeaderItem)
{
GridHeaderItem headerItem = (GridHeaderItem)e.Item;
TimesheetDetail weekday = ((TimesheetDetail)entTimesheetDetail.Where<TimesheetDetail>(tsd => tsd.Record_Type == "Weekday").Take<TimesheetDetail>(1).SingleOrDefault());
TimesheetDetail weekdate = ((TimesheetDetail)entTimesheetDetail.Where<TimesheetDetail>(tsd => tsd.Record_Type == "Weekdate").Take<TimesheetDetail>(1).SingleOrDefault());
headerItem["Day1"].Text = weekday.Day1 + "<BR>" + weekdate.Day1.ToString();
headerItem["Day2"].Text = weekday.Day2 + "<BR>" + weekdate.Day2.ToString();
headerItem["Day3"].Text = weekday.Day3 + "<BR>" + weekdate.Day3.ToString();
headerItem["Day4"].Text = weekday.Day4 + "<BR>" + weekdate.Day4.ToString();
headerItem["Day5"].Text = weekday.Day5 + "<BR>" + weekdate.Day5.ToString();
headerItem["Day6"].Text = weekday.Day6 + "<BR>" + weekdate.Day6.ToString();
headerItem["Day7"].Text = weekday.Day7 + "<BR>" + weekdate.Day7.ToString();
}
#endregion
#region FOOTER ITEM HANDLER
if (e.Item is GridFooterItem)
{
GridFooterItem footer = (GridFooterItem)e.Item;
footer["Day1"].Attributes.Add("name", footer["Day1"].ClientID);
footer["Day2"].Attributes.Add("name", footer["Day2"].ClientID);
footer["Day3"].Attributes.Add("name", footer["Day3"].ClientID);
footer["Day4"].Attributes.Add("name", footer["Day4"].ClientID);
footer["Day5"].Attributes.Add("name", footer["Day5"].ClientID);
footer["Day6"].Attributes.Add("name", footer["Day6"].ClientID);
footer["Day7"].Attributes.Add("name", footer["Day7"].ClientID);
footer["Total"].Attributes.Add("name", footer["Total"].ClientID);
if (isTimeCardEntry)
{
footer["IsTimeCard"].Text = "Total : ";
}
else
{
footer["Category"].Text = "Total : ";
}
TimesheetDetail aggregate = ((TimesheetDetail)entTimesheetDetail.Where<TimesheetDetail>(tsd => tsd.Record_Type == "Aggregate").Take<TimesheetDetail>(1).SingleOrDefault());
footer["Day1"].Text = aggregate.Day1.ToString();
footer["Day2"].Text = aggregate.Day2.ToString();
footer["Day3"].Text = aggregate.Day3.ToString();
footer["Day4"].Text = aggregate.Day4.ToString();
footer["Day5"].Text = aggregate.Day5.ToString();
footer["Day6"].Text = aggregate.Day6.ToString();
footer["Day7"].Text = aggregate.Day7.ToString();
footer["Total"].Text = aggregate.Total.ToString();
}
#endregion
if (e.Item is GridDataItem)
{
GridDataItem dataItem = (GridDataItem)e.Item;
CheckBox chk = (dataItem["IsTimeCard"].Controls[0] as CheckBox);
if (chk != null)
{
if (chk.Checked)
{
dataItem.BackColor = System.Drawing.Color.Red;
//dataItem.Font.Bold = true;
}
}
}
if (e.Item.ItemType == GridItemType.EditItem)
{
GridDataItem item = (GridDataItem)e.Item;
#region Sites Column
TextBox txtboxSite = (TextBox)(item["Site"].Controls[1]);
if (txtboxSite != null)
{
//txtboxSite.Attributes.Add("onblur", "javascript:return showSelected(this)");
string strScript = " return SelectSite(" + txtboxSite.ClientID + ");";
Image img = ((Image)item.FindControl("btnImg"));
if (img != null)
{
img.Attributes.Add("onclick", strScript);
}
}
else
{
txtboxSite.Text = String.Empty;
}
#endregion
#region Profit Center Column
HiddenField hdnProfCtr = (HiddenField)(item["ProfCtr"]).FindControl("hdnProfCtr");
HiddenField hdnSite = (HiddenField)(item["Site"]).FindControl("hdnSitetext");
if (Convert.ToBoolean(hTbl["Timesheet_Is_ProfCtr"]))
{
//Set profit center's formatted id
if (hdnSite != null)
{
List<ProfitCenter> list = new List<ProfitCenter>();
if (Session["profctrSite"] != null)
{
Entities<ProfitCenters> entProfitCenters = (Entities<ProfitCenters>)Session["profctrSite"];
foreach (ProfitCenters pc in entProfitCenters)
{
if (pc.SiteFormattedID == hdnSite.Value)
{
ProfitCenter profctr = new ProfitCenter();
profctr.ProfCtr_Key = pc.ProfCtrKey;
profctr.ProfCtr_Type_Desc = pc.ProfCtrName;
list.Add(profctr);
}
}
}
if (hdnProfCtr != null)
{
ProfitCenter profct = (ProfitCenter)list.Where<ProfitCenter>(pc => pc.ProfCtr_Key == hdnProfCtr.Value).Take<ProfitCenter>(1).SingleOrDefault();
TextBox txtbox = (TextBox)(item["ProfCtr"].Controls[1]);
if (profct != null && txtbox != null)
{
txtbox.Text = profct.ProfCtr_Type_Desc;
if (list.Count == 1)
{
txtbox.Enabled = false;
}
}
else
{
txtbox.Text = string.Empty;
}
HiddenField hdnpc = (HiddenField)(item["ProfCtr"]).FindControl("hdnProfCtrtext"); ;
if (profct != null && hdnpc != null)
{
hdnpc.Value = profct.ProfCtr_Type_Desc;
}
}
RadComboBox rComboBox = (RadComboBox)(item["ProfCtr"]).FindControl("cmbProfCtr");
if (rComboBox != null)
{
UIHelper.ClearComboBoxControl<RadComboBox>(rComboBox);
rComboBox.DataSource = list;
rComboBox.DataTextField = "ProfCtr_Type_Desc";
rComboBox.DataValueField = "ProfCtr_Key";
rComboBox.DataBind();
rComboBox.Items.Insert(0, new RadComboBoxItem(String.Empty, "0"));
rComboBox.SelectedValue = hdnProfCtr.Value;
}
}
}
#endregion
#region Work type column
//Work Types
HiddenField hdnSitetext = (HiddenField)(item["Site"]).FindControl("hdnSitetext");
string siteid = String.Empty;
string profctrid = String.Empty;
string ProfCtr_Type_Key = String.Empty;
if (hdnSitetext != null)
{
siteid = hdnSitetext.Value;
}
if (hdnProfCtr != null)
{
profctrid = hdnProfCtr.Value;
}
List<ValidWorkTypes> WTlist = new List<ValidWorkTypes>();
Entities<EmployeeWeeklyWorkTypes> entAllWorkTypes = EmployeeWorkTypeSource;
if (System.Web.HttpContext.Current.Session[WFConstants.TIMESHEET_PROFITCENTER_SITE] != null)
{
Entities<profdata.com.Entities.Framework.TimeClock.ProfitCenters> entProfitCenters = (Entities<profdata.com.Entities.Framework.TimeClock.ProfitCenters>)System.Web.HttpContext.Current.Session[WFConstants.TIMESHEET_PROFITCENTER_SITE];
ProfitCenters profCtr = (ProfitCenters)(entProfitCenters.Where<ProfitCenters>(pct => pct.ProfCtrKey == profctrid).Take<ProfitCenters>(1).SingleOrDefault());
if (profCtr != null)
{
ProfCtr_Type_Key = profCtr.ProfCtrType;
}
}
string businessEntityID = String.Empty;
if (profctrid == "0") profctrid = String.Empty;
DataTable dtbl = null;
if (Session["EmpAuthorizedSites"] != null)
{
dtbl = (DataTable)Session["EmpAuthorizedSites"];
}
else
{
if (Session[WFConstants.TIMESHEET_PARAMS] != null)
{
hTbl = (Hashtable)Session[WFConstants.TIMESHEET_PARAMS];
if (hTbl != null)
{
string emp_key = hTbl[WFConstants.TIMESHEET_HASHTABLE_EMPLOYEE_KEY].ToString();
string weekendingdate = hTbl[WFConstants.TIMESHEET_HASHTABLE_BUSINESS_ENDDATE].ToString();
UserInfo userInfo = new UserInfo();
CompanySites companySites = new CompanySites();
dtbl = companySites.GetEmployeesAuthorizedSites(userContext, userInfo.GetAssociatedEmployeeListFromContext((Page as PageBase).EmployeeContexts), emp_key, weekendingdate);
}
}
}
if (dtbl != null)
{
DataRow[] dr = dtbl.Select("ID='" + siteid + "'");
if (dr.Length > 0)
{
businessEntityID = dr[0]["BusEnts"].ToString();
}
}
foreach (EmployeeWeeklyWorkTypes ewt in entAllWorkTypes)
{
if (ewt.ProfCtr_Type_Key == String.Empty || ewt.ProfCtr_Type_Key == ProfCtr_Type_Key)
{
if (!String.IsNullOrEmpty(ewt.BusEntID))
{
string[] WTBeArr = ewt.BusEntID.Split(',');
string[] BeArr = businessEntityID.Split(',');
for (int i = 0; i < WTBeArr.Length; i++)
{
if (WTBeArr[i] != String.Empty)
{
for (int j = 0; j < BeArr.Length; j++)
{
if (BeArr[j] != String.Empty && BeArr[j] == WTBeArr[i])
{
ValidWorkTypes obj = new ValidWorkTypes();
obj.WorkTypeCode = ewt.WorkType_Code;
obj.WorkTypeKeyAndCategory = ewt.WorkType_KeyAndCategory;
WTlist.Add(obj);
}
}
}
}
}
else
{
ValidWorkTypes obj = new ValidWorkTypes();
obj.WorkTypeCode = ewt.WorkType_Code;
obj.WorkTypeKeyAndCategory = ewt.WorkType_KeyAndCategory;
WTlist.Add(obj);
}
}
}
HiddenField hdnworktype = (HiddenField)(item["WorkType"]).FindControl("hdnWorkType");
RadComboBox rComboBox_wt = (RadComboBox)(item["WorkType"]).FindControl("cmbWorkType");
if (rComboBox_wt != null)
{
UIHelper.ClearComboBoxControl<RadComboBox>(rComboBox_wt);
rComboBox_wt.DataSource = WTlist;
rComboBox_wt.DataTextField = "WorkTypeCode";
rComboBox_wt.DataValueField = "WorkTypeKeyAndCategory";
rComboBox_wt.DataBind();
rComboBox_wt.Items.Insert(0, new RadComboBoxItem(String.Empty, "0"));
rComboBox_wt.SelectedValue = hdnworktype.Value;
}
if (hdnworktype != null)
{
ValidWorkTypes worktype = (ValidWorkTypes)WTlist.Where<ValidWorkTypes>(pc => pc.WorkTypeKeyAndCategory == hdnworktype.Value).Take<ValidWorkTypes>(1).SingleOrDefault();
TextBox txtbox = (TextBox)(item["WorkType"].Controls[1]);
if (worktype != null && txtbox != null)
{
txtbox.Text = worktype.WorkTypeCode;
if (WTlist.Count == 1)
{
txtbox.Enabled = false;
}
}
else
{
HiddenField hdnworktypeCode = (HiddenField)(item["WorkType"]).FindControl("hdnWorkTypeCode");
if (hdnworktypeCode != null && txtbox != null)
{
txtbox.Text = hdnworktypeCode.Value;
}
}
}
#endregion
}
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void grdTimesheet_PreRender(object sender, EventArgs e)
{
try
{
GetParentPage();
grdTimesheet.Attributes.Add("onkeydown", "onKeyDown(this,event);");
int itemsCount = 0;
int columnsCount = 0;
bool isReadOnlyRow = false;
bool isGridDisabled = false;
bool isNeddRecalc = false;
bool isAllTimeCardEntry = true;
Hashtable hTbl = new Hashtable();
if (Session[WFConstants.TIMESHEET_PARAMS] != null)
{
hTbl = (Hashtable)Session[WFConstants.TIMESHEET_PARAMS];
//btnGoToTimeCard.Visible = false;
if (hTbl != null && hTbl["TimesheetStatus"] != null && hTbl["TimesheetStatus"].ToString() != "" && hTbl["TimesheetStatus"].ToString() != "1")
{
isGridDisabled = true;
}
if (hTbl["ViewType"] != null && hTbl["ViewType"].ToString() != String.Empty)
{
ViewType = (TimesheetViewType)hTbl["ViewType"];
}
if (hTbl["IsNeedRecalc"] != null && hTbl["IsNeedRecalc"].ToString() != "" && Convert.ToBoolean(hTbl["IsNeedRecalc"].ToString()))
{
isNeddRecalc = true;
}
}
CompanySites companySites = new CompanySites();
if (Session["OldTimeSheet"] != null)
{
Entities<TimesheetDetail> entTimesheetDetail = (Entities<TimesheetDetail>)Session["OldTimeSheet"];
// Attach the event handlers to the client side events of the TextBoxes. 
foreach (GridItem item in grdTimesheet.MasterTableView.Items)
{
if (item is GridDataItem)
{
GridDataItem dataItem = (GridDataItem)item;
columnsCount = 0;
isReadOnlyRow = (dataItem["IsTimeCard"].Controls[0] as CheckBox).Checked;
if (!isReadOnlyRow)
{
isAllTimeCardEntry = false;
}
#region toggle visibility of delete icon of a grid
LinkButton lnkDelete = (dataItem["Delete"].Controls[1]) as LinkButton;
if ((this.Page as PageBase).SecurityRights == enmSecurityRights.ReadOnly)
{
if (lnkDelete != null)
{
lnkDelete.Enabled = false;
lnkDelete.Style.Add("cursor", "default");
}
else
{
lnkDelete.Attributes.Remove("style");
}
}
else if (isReadOnlyRow)
{
if (lnkDelete != null)
{
lnkDelete.Visible = false;
}
}
else if (isGridDisabled || IsTimeSheetSubmitted || isNeddRecalc)
{
if (lnkDelete != null)
{
lnkDelete.Enabled = false;
lnkDelete.Style.Add("cursor", "default");
}
else
{
lnkDelete.Attributes.Remove("style");
}
}
#endregion
if (!CheckFunctionalSecurityRights())
{
HiddenField hdnSiteFormatted = dataItem["Site"].Controls[5] as HiddenField;
if (hdnSiteFormatted != null)
{
#region Site Manager foreign site gray out
if (ViewType == TimesheetViewType.SiteManager || ViewType == TimesheetViewType.Administrator)
{
userContext = (this.Page as PageBase).CurrentUserContext;
string site_desc = String.Empty;
string sitekey = companySites.GetSiteKey(userContext, hdnSiteFormatted.Value, out site_desc);
if (entTimesheetDetail.Count > item.ItemIndex && !String.IsNullOrEmpty(entTimesheetDetail[item.ItemIndex].Timesheet_Key) && !String.IsNullOrEmpty(hdnSiteFormatted.Value) && hdnSiteFormatted.Value != "0" && !companySites.IsSitePermitted(userContext, sitekey))
{
dataItem.Enabled = false;
(this.Parent.Page.Master as workforce).DeleteEnabled = false;
if (lnkDelete != null)
{
lnkDelete.Enabled = false;
lnkDelete.Style.Add("cursor", "default");
}
}
}
#endregion
}
}
HiddenField hdnOpenShify = dataItem["OpenShiftDays"].Controls[1] as HiddenField;
for (int i = 2; i < grdTimesheet.MasterTableView.RenderColumns.Length; i++)
{
GridColumn column = grdTimesheet.MasterTableView.RenderColumns[i];
if (column.UniqueName != "IsTimeCard" && column.UniqueName != "Category" && column.UniqueName != "Total")
{
TextBox textBox = (dataItem[column.UniqueName].Controls[0]) as TextBox;
if (textBox != null)
{
textBox.Attributes.Add("style", "text-align:center");
if (isReadOnlyRow || isGridDisabled || IsTimeSheetSubmitted || isNeddRecalc)
{
if (isReadOnlyRow && hdnOpenShify != null && i >= 8 && hdnOpenShify.Value.Contains((i - 7).ToString()))
{
string open = hdnOpenShify.Value;
((TableCell)textBox.Parent).CssClass = "errorSelect";
textBox.Attributes.Add("class", "errorSelect");
textBox.Attributes.Add("disabled", "disabled");
}
else
{
textBox.ReadOnly = true;
textBox.Attributes.Add("class", "input");
((TableCell)textBox.Parent).Style.Add("background-color", "#F5F5F5");
}
}
else
{
textBox.Attributes.Add("onclick", "cellClick('" + textBox.ClientID + "');");
textBox.Attributes.Add("onchange", "horizontalTotal('" + textBox.ClientID + "');");
textBox.Attributes.Add("onblur", "horizontalTotal('" + textBox.ClientID + "');");
textBox.Attributes.Add("onKeyPress", "return checkIt(event);");
if (textBox.Text != String.Empty && !ValidInput(textBox.Text))
{
if (column.UniqueName != "Total")
{
((TableCell)textBox.Parent).CssClass = "errorSelect";
textBox.Attributes.Add("class", "errorSelect");
}
}
else
{
((TableCell)textBox.Parent).CssClass = "";
textBox.Attributes.Add("class", "input");
}
textBox.MaxLength = 5;
}
}
else if (column.UniqueName == "Site")
{
TextBox txtSiteBox = (TextBox)dataItem[column.UniqueName].Controls[1];
if (isReadOnlyRow || isGridDisabled || IsTimeSheetSubmitted || isNeddRecalc)
{
txtSiteBox.Attributes.Add("style", "text-align:center");
txtSiteBox.ReadOnly = true;
txtSiteBox.Attributes.Add("class", "input");
((TableCell)txtSiteBox.Parent).Style.Add("background-color", "#F5F5F5");
}
else
{
HtmlTable tblSite = (dataItem[column.UniqueName].FindControl("cmbSite")) as HtmlTable;
txtSiteBox.Attributes.Add("style", "text-align:center");
txtSiteBox.Attributes.Add("class", "input");
txtSiteBox.Attributes.Add("onclick", "textclick('" + txtSiteBox.ClientID + "');");
tblSite.Attributes.Add("onmouseout", "hideSite('" + txtSiteBox.ClientID + "');");
}
}
else if (column.UniqueName == "ProfCtr" || column.UniqueName == "WorkType")
{
textBox = (TextBox)dataItem[column.UniqueName].Controls[1];
RadComboBox radComboBox = (dataItem[column.UniqueName].FindControl("cmb" + column.UniqueName)) as RadComboBox;
if (textBox != null)
{
if (isReadOnlyRow || isGridDisabled || IsTimeSheetSubmitted || isNeddRecalc)
{
textBox.Attributes.Add("style", "text-align:center");
textBox.ReadOnly = true;
textBox.Attributes.Add("class", "input");
((TableCell)textBox.Parent).Style.Add("background-color", "#F5F5F5");
}
else
{
textBox.Attributes.Add("style", "text-align:center");
textBox.Attributes.Add("class", "input");
textBox.Attributes.Add("onclick", "textclick('" + textBox.ClientID + "');");
}
}
if (radComboBox != null)
{
if (isReadOnlyRow || isGridDisabled || IsTimeSheetSubmitted || isNeddRecalc)
{
radComboBox.Enabled = false;
}
}
}
}
columnsCount++;
}
itemsCount++;
}
else if (item is GridFooterItem)
{
GridFooterItem footerItem = (GridFooterItem)item;
for (int i = 2; i < grdTimesheet.MasterTableView.RenderColumns.Length; i++)
{
GridColumn column = grdTimesheet.MasterTableView.RenderColumns[i];
TextBox textBox = (footerItem[column.UniqueName].Controls[0]) as TextBox;
if (textBox != null)
{
textBox.Text = i.ToString();
}
columnsCount++;
}
}
}
if (grdTimesheet.MasterTableView.Items.Count == 0)
{
isAllTimeCardEntry = false;
}
RadScriptManager.RegisterStartupScript(Page, Page.GetType(), "init", "colls = " + 17 + ";rows=" + itemsCount + ";", true);
//Set buttons visibility
btnSubmit.Text = "Submit";
btnComments.Visible = false;
// Do not show comments when Timesheet is not created
if (hTbl["TimesheetKey"] != null && hTbl["TimesheetKey"].ToString() != String.Empty)
{
btnComments.Visible = (ViewType != TimesheetViewType.Employee ? true : false);
btnRevalidateTimecard.Visible = (ViewType != TimesheetViewType.Employee ? true : false);
if (hTbl["TimeCardErrors"] != null && hTbl["TimeCardErrors"].ToString() != String.Empty && hTbl["TimeCardErrors"].ToString() != "0")
{
if (isTimeCardEntry)
{
btnRevalidateTimecard.Enabled = true;
}
}
btnComments.Text = "Show Comments (" + Comments + ")...";
//btnSubmit.Visible = true;
if (hTbl != null && (hTbl["TimesheetStatus"].ToString() == "" || hTbl["TimesheetStatus"].ToString() == "1"))
{
btnSubmit.Text = "Submit";
}
else
{
btnSubmit.Text = "Reopen";
}
}
btnGoToTimeCard.Enabled = isTimeCardEntry; // enabled if there is at least one timecard entry
btnAuditHistory.Visible = (ViewType != TimesheetViewType.Employee ? true : false); //visible to site manger and administrator
btnApprovalStatus.Visible = (ViewType != TimesheetViewType.Employee ? true : false); //visible to only administrator
if (IsTimeSheetSubmitted)
{
btnSubmit.Text = "Reopen";
}
if (grdTimesheet.MasterTableView.Items.Count == 0 || isNeddRecalc ||
(hTbl.Contains("TimeCardErrors") && !String.IsNullOrEmpty(hTbl["TimeCardErrors"].ToString())
&& int.Parse(hTbl["TimeCardErrors"].ToString()) > 0))
{
btnSubmit.Enabled = false;
}
else
{
btnSubmit.Enabled = true;
}
if (isAllTimeCardEntry && ViewType == TimesheetViewType.Employee)
{
btnSubmit.Visible = false;
}
else
{
btnSubmit.Visible = true;
}
// Do not show comments when Timesheet is not created
if (hTbl["TimesheetKey"] != null && hTbl["TimesheetKey"].ToString() != String.Empty)
{
btnComments.Visible = (ViewType != TimesheetViewType.Employee ? true : false);
btnRevalidateTimecard.Visible = (ViewType != TimesheetViewType.Employee ? true : false);
if (hTbl["TimeCardErrors"] != null && hTbl["TimeCardErrors"].ToString() != String.Empty && hTbl["TimeCardErrors"].ToString() != "0")
{
if (isTimeCardEntry)
{
btnRevalidateTimecard.Enabled = true;
}
}
btnComments.Text = "Show Comments (" + Comments + ")...";
//btnSubmit.Visible = true;
//if (hTbl != null && (hTbl["TimesheetStatus"].ToString() == "" || hTbl["TimesheetStatus"].ToString() == "1"))
//{
// btnSubmit.Enabled = true;
// btnSubmit.Text = "Submit";
//}
//else
//{
// btnSubmit.Enabled = true;
// btnSubmit.Text = "Reopen";
//}
}
if (grdTimesheet.MasterTableView.Items.Count == 0 && btnSubmit.Text == "Submit")
{
btnSubmit.Enabled = false;
}
if ((this.Page as PageBase).SecurityRights == enmSecurityRights.ReadOnly)
{
btnRevalidateTimecard.Enabled = false;
btnSubmit.Enabled = false;
}
}
ResetDirtyChanges();
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 
/// </summary>
/// <param name="source"></param>
/// <param name="e"></param>
protected void grdTimesheet_ItemCommand(object source, GridCommandEventArgs e)
{
try
{
saveTimesheetDetails();
switch (e.CommandName)
{
case "InsertNewRow":
{
//if submitted fo not add a new row
if (Session[WFConstants.TIMESHEET_PARAMS] != null)
{
Hashtable hTbl = new Hashtable();
hTbl = (Hashtable)Session[WFConstants.TIMESHEET_PARAMS];
if (hTbl != null && hTbl["TimesheetStatus"] != null && hTbl["TimesheetStatus"].ToString() != "" && hTbl["TimesheetStatus"].ToString() != "1")
{
return;
}
CreateNewEntry(ExcelGridSource, 1, 1);
ShowHideProfitCenterAndTimeCardColumn();
IsDirtyOn = true;
grdTimesheet.Rebind();
string clinetname = e.CommandArgument.ToString().Substring(0, e.CommandArgument.ToString().LastIndexOf('l') + 1);
clinetname = clinetname + "01";
string script = "setTimeout( function () { selectedCellId='" + clinetname + "'; MoveDown();},100);";
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "selectCell", script, true);
}
//set dirty grid flag to true 
SetGridDirty();
}
break;
case "AddNewRow":
{
CreateNewEntry(ExcelGridSource, 1, 1);
ShowHideProfitCenterAndTimeCardColumn();
IsDirtyOn = true;
grdTimesheet.Rebind();
//set dirty grid flag to true 
SetGridDirty();
}
break;
case "DeleteSelected":
{
IsDirtyOn = true;
if (e.Item is GridDataItem)
{
GridDataItem dataItem = (GridDataItem)e.Item;
string rowNum = (dataItem["RowNumber"].Controls[0] as TextBox).Text;
if (rowNum != "")
{
RadWindow Window = WinMgr.Windows[1];
Window.VisibleOnPageLoad = true;
Window.Width = Unit.Pixel(300);
Window.Height = Unit.Pixel(240);
Window.Modal = true;
ViewState["RowNumber"] = rowNum;
ShowHideProfitCenterAndTimeCardColumn();
grdTimesheet.Rebind();
HideErrorWarning(null);
}
}
//set dirty grid flag to true 
SetGridDirty();
}
break;
default: break;
}
}
catch (Exception ex)
{
throw ex;
}
}
#endregion

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 03 Nov 2011, 09:38 AM
Hello Shimab,

In order to optimize the control performance on the client, you may consider:

  1. Turning off all client features of the grid
  2. Turning off all row-related features (row select, row click, etc.). When enabling even a single client side row functionality, the grid adds additional scripts to the page which can slow down the performance of the product.
  3. Use built-in/custom paging or virtual scrolling/paging and present only fixed set of records at a time - here are online examples for it:

Here is the  help documentation which explains more about this.
Client/server grid performance optimizations

Thanks,
Shinu.
Tags
Grid
Asked by
Shimab
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or