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

RadGrid1_DetailTableDataBind event is firing on every opraton of RadGrid

3 Answers 252 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rasheed
Top achievements
Rank 1
Rasheed asked on 01 Oct 2014, 06:08 AM
We have Telerik Radgrid with master and detail table.
I'm binding Radgrid in page-load event/method.
i have OnDetailTableDataBind="RadGrid1_DetailTableDataBind" method also where i'm binding details table based on key values.
on every operations like filtering, paging page-load method is calling so RadGrid1_DetailTableDataBind is also firing for every operation.
So performance of Grid is slow when paging is performing...
Can u guide me what is the best way to improve the performance of Grid with master and details tables when we have thousands of records?
Immediate response is appreciated...

Thanks & Regards,
Rasheed Siriyala

3 Answers, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 03 Oct 2014, 01:16 PM
Hello Rasheed,

Actually calling of NeedDataSource and DetailTableDataBind after operations such as filtering, sorting paging etc. is expected since the data in the MasterTableView and DetailTableView is changed. Basically you are populating the tables with a new data after each of the aforementioned operations. Nevertheless there is a different hierarchy load modes which call DetailTableDataBind event for all tables or only for the visible ones. Please check out the following help article which elaborates more on this matter and choose the appropriate load mode for your case.

Regards,
Kostadin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Rasheed
Top achievements
Rank 1
answered on 15 Oct 2014, 02:38 PM
Thanks for your Reply Kostadin.
I have implemented hierarchial radgrid with OnNeedDataSource and DetailTableDataBind and using HierarchyLoadMode="ServerOnDemand".
My Code is in attachments.
On paging its taking close to 6-10 seconds which is very poor for very few records which are around 100.
On expand it is taking close to 5 sec, for 10 records.
After expansion, Collapse is not working for child grid.
Below is my code,
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Dashboard.ascx.cs" Inherits="adidas.wfs.Security_DMWeb.UserControls.Dashboard" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>

<link href="../Security_DM/CSS/securityDM.css" rel="Stylesheet" type="text/css" />

<div>
    <div class="exp-dir">
    Export Current Data    
    <asp:ImageButton ID="ibExpCurData" runat="server" ImageUrl="~/Security_DM/Images/excel2.png"
        OnClick="ibExpCurData_Click" AlternateText="ExcelML" Width="30px" Height="30px" />
    &nbsp;&nbsp; Export All Data
    <asp:ImageButton ID="ibExpAllData" runat="server" ImageUrl="~/Security_DM/Images/excel2.png"
        OnClick="ibExpAllData_Click" AlternateText="ExcelML" Width="30px" Height="30px" />
    </div>
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    </telerik:RadScriptManager>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
        <div>
            <asp:Image ID="Image2" runat="server" ImageUrl="~/Security_DM/Images/Loading.gif" AlternateText="loading"
                Style="margin: 100px auto 50px auto;" />
        </div>
    </telerik:RadAjaxLoadingPanel>
    
    <telerik:RadGrid ID="RadGrid1" runat="server"  CellSpacing="0" AutoGenerateColumns="False"
        MasterTableView-AllowFilteringByColumn="true" AllowSorting="true" GridLines="None"
        MasterTableView-AllowPaging="true"  EnableViewState="false"
        OnExcelMLWorkBookCreated="RadGrid1_ExcelMLWorkBookCreated"
        OnNeedDataSource="RadGrid1_NeedDataSource"        
        OnDetailTableDataBind="RadGrid1_DetailTableDataBind"
        >
       
            <PagerStyle Mode="NextPrevAndNumeric" AlwaysVisible="true"></PagerStyle>
            <GroupingSettings CaseSensitive="false" />
            <ClientSettings EnableRowHoverStyle="true">
                <Resizing AllowColumnResize="true" EnableRealTimeResize="true" 
                    ResizeGridOnColumnResize="true" ClipCellContentOnResize="true" />
                <Selecting AllowRowSelect="true" />                
            </ClientSettings>
            <MasterTableView HierarchyLoadMode="ServerOnDemand" EnableViewState="false" AllowSorting="true" 
                DataKeyNames="ParentCaseID, CaseID" Font-Size="13px">
                <DetailTables>
                <telerik:GridTableView DataKeyNames="CaseID" EnableViewState="false" 
                    ShowHeader="false" Font-Size="13px">
                    <Columns>
                    <telerik:GridHyperLinkColumn HeaderText="Request Number" Target="_blank" DataTextFormatString="{0}" DataNavigateUrlFields="CaseURL"
                        UniqueName="CaseRadicationNumber" 
                        DataTextField="CaseRadicationNumber" CurrentFilterFunction="Contains" AutoPostBackOnFilter="true"
                        >
                    </telerik:GridHyperLinkColumn>
                   <%-- <telerik:GridBoundColumn SortExpression="CaseRadicationNumber" HeaderText="Request Number" HeaderButtonType="TextButton" 
                        DataField="CaseRadicationNumber" UniqueName="CaseRadicationNumber" CurrentFilterFunction="Contains" AutoPostBackOnFilter="true">
                    </telerik:GridBoundColumn>--%>
                    <telerik:GridBoundColumn SortExpression="RequestSubject" HeaderText="Request Subject" HeaderButtonType="TextButton" 
                        DataField="RequestSubject" UniqueName="RequestSubject" CurrentFilterFunction="Contains" AutoPostBackOnFilter="true">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn SortExpression="SubmissionDate" HeaderText="Submission Date" HeaderButtonType="TextButton" 
                        DataField="SubmissionDate" UniqueName="SubmissionDate" DataFormatString="{0:dd/MM/yyyy}" CurrentFilterFunction="Contains" AutoPostBackOnFilter="true">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn SortExpression="RequestorName" HeaderText="Requestor Name" HeaderButtonType="TextButton" 
                        DataField="RequestorName" UniqueName="RequestorName" CurrentFilterFunction="Contains" AutoPostBackOnFilter="true">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn SortExpression="LastActionDate" HeaderText="Last Action Date" HeaderButtonType="TextButton" 
                        DataField="LastActionDate" UniqueName="LastActionDate" DataFormatString="{0:dd/MM/yyyy}" CurrentFilterFunction="Contains" AutoPostBackOnFilter="true">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn SortExpression="CaseCompletionDate" HeaderText="Completion Date" HeaderButtonType="TextButton" 
                        DataField="CaseCompletionDate" UniqueName="CaseCompletionDate" DataFormatString="{0:dd/MM/yyyy}" CurrentFilterFunction="Contains" AutoPostBackOnFilter="true">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn SortExpression="CurrentAssignee" HeaderText="Current Assignee" HeaderButtonType="TextButton" 
                        DataField="CurrentAssignee" UniqueName="CurrentAssignee" CurrentFilterFunction="Contains" AutoPostBackOnFilter="true">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn SortExpression="StatusDescription" HeaderText="Status" HeaderButtonType="TextButton" 
                        DataField="StatusDescription" UniqueName="StatusDescription" CurrentFilterFunction="Contains" AutoPostBackOnFilter="true">
                    </telerik:GridBoundColumn>
                    </Columns>
                </telerik:GridTableView>
            </DetailTables>
            <Columns>
                <telerik:GridTemplateColumn UniqueName="selectDraftReq" AllowFiltering="false" HeaderStyle-Width="50px">
                        <ItemTemplate>
                            <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" 
                                OnCheckedChanged="CheckBox1_CheckedChanged"/>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                <telerik:GridHyperLinkColumn HeaderText="Request Number" Target="_blank" DataTextFormatString="{0}" DataNavigateUrlFields="CaseURL"
                    UniqueName="CaseRadicationNumber" DataType="System.Int32" AllowSorting="true" SortExpression="" AllowFiltering="true"
                    DataTextField="CaseRadicationNumber" CurrentFilterFunction="Contains" AutoPostBackOnFilter="true" FilterControlWidth="75px">
                </telerik:GridHyperLinkColumn>
                <%--<telerik:GridBoundColumn SortExpression="CaseRadicationNumber" HeaderText="Request Number" 
                    HeaderButtonType="TextButton" DataField="CaseRadicationNumber" UniqueName="CaseRadicationNumber" 
                    CurrentFilterFunction="Contains" AutoPostBackOnFilter="true" FilterControlWidth="75px">
                </telerik:GridBoundColumn>--%>
                <telerik:GridBoundColumn SortExpression="RequestSubject" HeaderText="Request Subject" 
                    HeaderButtonType="TextButton" DataField="RequestSubject" UniqueName="RequestSubject" 
                    CurrentFilterFunction="Contains" AutoPostBackOnFilter="true" FilterControlWidth="75px">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn SortExpression="SubmissionDate" HeaderText="Submission Date" 
                    HeaderButtonType="TextButton" DataField="SubmissionDate" UniqueName="SubmissionDate" 
                    DataFormatString="{0:dd/MM/yyyy}" CurrentFilterFunction="Contains" AutoPostBackOnFilter="true" 
                    FilterControlWidth="75px">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn SortExpression="RequestorName" HeaderText="Requestor Name" 
                    HeaderButtonType="TextButton" DataField="RequestorName" UniqueName="RequestorName" 
                    CurrentFilterFunction="Contains" AutoPostBackOnFilter="true" FilterControlWidth="75px">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn SortExpression="LastActionDate" HeaderText="Last Action Date" 
                    HeaderButtonType="TextButton" DataField="LastActionDate" UniqueName="LastActionDate" 
                    DataFormatString="{0:dd/MM/yyyy}" CurrentFilterFunction="Contains" AutoPostBackOnFilter="true"
                    FilterControlWidth="75px">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn SortExpression="CaseCompletionDate" HeaderText="Completion Date" 
                    HeaderButtonType="TextButton" DataField="CaseCompletionDate" UniqueName="CaseCompletionDate" 
                    DataFormatString="{0:dd/MM/yyyy}" CurrentFilterFunction="Contains" AutoPostBackOnFilter="true" 
                    FilterControlWidth="75px">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn SortExpression="CurrentAssignee" HeaderText="Current Assignee" 
                    HeaderButtonType="TextButton" DataField="CurrentAssignee" UniqueName="CurrentAssignee" 
                    CurrentFilterFunction="Contains" AutoPostBackOnFilter="true" FilterControlWidth="75px">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn SortExpression="StatusDescription" HeaderText="Status" 
                    HeaderButtonType="TextButton" DataField="StatusDescription" UniqueName="StatusDescription" 
                    CurrentFilterFunction="Contains" AutoPostBackOnFilter="true" FilterControlWidth="75px">
                </telerik:GridBoundColumn>
            </Columns>        
            </MasterTableView>
            <ClientSettings AllowExpandCollapse="true" />
        </telerik:RadGrid>        
</div>

Below is my code behind,
//-----------------------------------------------------------
// <copyright file="TelerikGrid.aspx.cs" company="adidas AG">
// Copyright (C) 2014 adidas AG.
// </copyright>
//-----------------------------------------------------------
namespace adidas.wfs.Security_DMWeb.UserControls
{
    using adidas.wfs.Security_DM.AppCode.Exceptions;
    using adidas.wfs.Security_DM.AppCode.Utility;
    using adidas.wfs.Security_DM.AppData;
    using adidas.wfs.Security_DM.AppLogic;
    using System;
    using System.Data;
    using System.Linq;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Web.UI;
    using Telerik.Web.UI.GridExcelBuilder;
    using System.Web.SessionState;
    using System.Web;
    using adidas.wfs.Security_DMWeb.AppCode.Utility;

    /// <summary>
    /// Displays requests in Grid and exports grid data to excel
    /// </summary>
    public partial class Dashboard : System.Web.UI.UserControl
    {
        // GridLog object
        GridLog gridLog;
        // datetime variable
        DateTime dateTime;
        /// <summary>
        /// Sets ParentCaseId value to 0 if the value is Null and stores page url in session variable
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            gridLog = new GridLog();
            // DashBoard PageLoad Start
            dateTime = System.DateTime.Now;
            gridLog.LogMsgToFile("\n\n\n___________ Dashboard PageLoad Start___________");
            try
            {
                // Log the method entry.
                Utilities.LogMessage(" Entry ", CoreConstants.Priority.Normal, CoreConstants.Category.General);

                // Session variable to store the page url.
                Session["SPHostUrl"] = Page.Request["SPHostUrl"];
                
                // Populate Dashboard
                //PopulateDashboard();
                
                
                //if (RadGrid1.EnableLinqExpressions)
                //{
                //    RadGrid1.MasterTableView.FilterExpression =
                //        @"(Convert.ToInt32(iif(it[""ParentCaseID""]==Convert.DBNull,null,it[""ParentCaseID""])) = 0)";
                //}
                //else
                //{
                //    RadGrid1.MasterTableView.FilterExpression = "ParentCaseID IS NULL";
                //} 

                // Log the method exit.
                Utilities.LogMessage(" Exit ", CoreConstants.Priority.Normal, CoreConstants.Category.General);

            }
            catch (UserInterfaceException exception)
            {
                // Log the error message to BizAgi DB.
                Utilities.LogMessage(exception.ToString(), CoreConstants.Priority.High, CoreConstants.Category.Trace);

                // Log the error message to SharePoint.
                Utilities.LogMessageToSharePoint(exception.ToString(),
                    CoreConstants.Priority.High, CoreConstants.Category.Trace);
            }
            gridLog.LogMsgToFile("___________ Dashboard PageLoad End___________ Time Taken:" + (System.DateTime.Now - dateTime).ToString() + " ms");
                      
        }

        /// <summary>
        /// Export current grid data to Excel
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ibExpCurData_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                // Log the method entry.
                Utilities.LogMessage(" Entry ", CoreConstants.Priority.Normal, CoreConstants.Category.General);

                string alternateText = (sender as ImageButton).AlternateText;

                //RadGrid1.Rebind();
                RadGrid1.ExportSettings.Excel.Format = (GridExcelExportFormat)Enum.Parse(typeof(GridExcelExportFormat), alternateText);
                
                // Enable paging.
                RadGrid1.ExportSettings.IgnorePaging = false;

                // Enable filtering.
                RadGrid1.MasterTableView.AllowFilteringByColumn = true;

                // Set property to export only data.
                RadGrid1.ExportSettings.ExportOnlyData = true;

                // Set Excel sheet to open in new window.
                RadGrid1.ExportSettings.OpenInNewWindow = true;

                // Set to Export all data fields of master table.
                RadGrid1.MasterTableView.UseAllDataFields = true;

                //RadGrid1.MasterTableView.HierarchyDefaultExpanded = true;
                //RadGrid1.MasterTableView.DetailTables[0].HierarchyDefaultExpanded = true;

                // Set property to export all rows in hierarchial manner.
                RadGrid1.MasterTableView.HierarchyLoadMode = GridChildLoadMode.Client;                
                RadGrid1.MasterTableView.DetailTables[0].HierarchyLoadMode = GridChildLoadMode.Client;

                // Call ExportToExcel
                RadGrid1.MasterTableView.ExportToExcel();

                // Log the method exit.
                Utilities.LogMessage(" Exit ", CoreConstants.Priority.Normal, CoreConstants.Category.General);
            }
            catch (UserInterfaceException exception)
            {
                // Log the error message to BizAgi DB.
                Utilities.LogMessage(exception.ToString(), CoreConstants.Priority.High, CoreConstants.Category.Trace);

                // Log the error message to SharePoint.
                Utilities.LogMessageToSharePoint(exception.ToString(),
                    CoreConstants.Priority.High, CoreConstants.Category.Trace);
            }
        }

        /// <summary>
        /// Export entire grid data to Excel.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ibExpAllData_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                // Log the method entry.
                Utilities.LogMessage(" Entry ", CoreConstants.Priority.Normal, CoreConstants.Category.General);

                string alternateText = (sender as ImageButton).AlternateText;
                // RadGrid3.RetainExpandStateOnRebind = true;
                RadGrid1.ExportSettings.Excel.Format = (GridExcelExportFormat)Enum.Parse(typeof(GridExcelExportFormat), alternateText);

                // Disable paging.
                RadGrid1.ExportSettings.IgnorePaging = true;

                // Disable filtering.
                RadGrid1.MasterTableView.AllowFilteringByColumn = false;

                // Set property to export only data.
                RadGrid1.ExportSettings.ExportOnlyData = true;

                // Set Excel sheet to open in new window.
                RadGrid1.ExportSettings.OpenInNewWindow = true;

                // Set to Export all data fields of master table.
                RadGrid1.MasterTableView.UseAllDataFields = true;

                // Set to export all rows in grid by expaning.
                RadGrid1.MasterTableView.HierarchyDefaultExpanded = true;
                RadGrid1.MasterTableView.DetailTables[0].HierarchyDefaultExpanded = true;

                // Set property to export all rows in hierarchial manner.
                RadGrid1.MasterTableView.HierarchyLoadMode = GridChildLoadMode.Client;
                RadGrid1.MasterTableView.DetailTables[0].HierarchyLoadMode = GridChildLoadMode.Client;

                RadGrid1.MasterTableView.ExportToExcel();

                // Log the method exit.
                Utilities.LogMessage(" Exit ", CoreConstants.Priority.Normal, CoreConstants.Category.General);
            }
            catch (UserInterfaceException exception)
            {
                // Log the error message to BizAgi DB.
                Utilities.LogMessage(exception.ToString(), CoreConstants.Priority.High, CoreConstants.Category.Trace);

                // Log the error message to SharePoint.
                Utilities.LogMessageToSharePoint(exception.ToString(),
                    CoreConstants.Priority.High, CoreConstants.Category.Trace);
            }
        }

        /// <summary>
        /// Binds requests data to Dashboard grid
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            DateTime dateTimeND = System.DateTime.Now;
            gridLog.LogMsgToFile("___________ NeedDataSource Start___________");

            // Initiate business logic object.
            BLLController bllController = new BLLController();

            // dtGrid DataTable object to store requests data.
            DataTable dtGrid = new DataTable();

            // Initialize userName string variable to store userName session value.
            string userName=string.Empty;

            // Initialize userRoles string variable to stroe userRoles session value.
            string userRoles = string.Empty;

            // Initialize userReq string variable to store gridFilter session value.
            string userReq = string.Empty;

            try
            {
                // Log the method entry.
                Utilities.LogMessage(" Entry ", CoreConstants.Priority.Normal, CoreConstants.Category.General);


                // Get userName session value if not null.
                if (Session["userName"] != null)
                {
                    userName = Session["userName"].ToString();
                }

                // Get userRole session value if not null.
                if (Session["userRoles"] != null)
                {
                    userRoles = Session["userRoles"].ToString();
                }

                // Get gridFilter session value if not null.
                if (Session["gridFilter"] != null)
                {
                    userReq = Session["gridFilter"].ToString();
                }

                if(userReq.ToLower().Contains("inprocess"))
                {
                    // map dtGrid with requests results datatable.
                    dtGrid = bllController.GetInProcessRequests("wijnemar", userRoles);

                    // Map MasterTable of RadGrid1 if the GridNeedDataSource is not from DetailTable.
                        RadGrid1.DataSource = dtGrid;
                    
                    // Display and hide columns as per request.
                    GridColumnsDisplay(false, true, true,false);
                    //RadGrid1.DataBind();
                }
                else if (string.IsNullOrEmpty(Convert.ToString(Session["gridFilter"])) || userReq.ToLower().Contains("waiting"))
                {
                    // map dtGrid with requests results datatable.
                    dtGrid = bllController.GetWaitingForMyActionRequests("wijnemar");

                    // Map MasterTable of RadGrid1 if the GridNeedDataSource is not from DetailTable.

                    RadGrid1.DataSource = dtGrid;

                    // Display and hide columns as per request.
                    GridColumnsDisplay(false, true, false,true);
                }
                else if (userReq.ToLower().Contains("delegate"))
                {
                    // map dtGrid with requests results datatable.
                    dtGrid = bllController.GetDelegateRequests("wijnemar");

                    // Map MasterTable of RadGrid1 if the GridNeedDataSource is not from DetailTable.

                    RadGrid1.DataSource = dtGrid;

                    // Display and hide columns as per request.
                    GridColumnsDisplay(false, true, true,false); 
                }
                else if (userReq.ToLower().Contains("closed"))
                {
                    // map dtGrid with requests results datatable.
                    dtGrid = bllController.GetClosedRequests("wijnemar", userRoles);

                    // Map MasterTable of RadGrid1 if the GridNeedDataSource is not from DetailTable.

                    RadGrid1.DataSource = dtGrid;

                    // Display and hide columns as per request.
                    GridColumnsDisplay(true, false, false,false);
                }

                // Log the method exit.
                Utilities.LogMessage(" Exit ", CoreConstants.Priority.Normal, CoreConstants.Category.General);
            }
            catch (UserInterfaceException exception)
            {
                // Log the error message to BizAgi DB.
                Utilities.LogMessage(exception.ToString(), CoreConstants.Priority.High, CoreConstants.Category.Trace);

                // Log the error message to SharePoint.
                Utilities.LogMessageToSharePoint(exception.ToString(),
                    CoreConstants.Priority.High, CoreConstants.Category.Trace);
            }
            gridLog.LogMsgToFile("___________ NeedDataSource End___________ Time Taken:" + (System.DateTime.Now - dateTimeND).ToString() + " ms");
            
        }
        

        /// <summary>
        /// Sets styling to the excel sheet generated
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void RadGrid1_ExcelMLWorkBookCreated(object sender, Telerik.Web.UI.GridExcelBuilder.GridExcelMLWorkBookCreatedEventArgs e)
        {
            try
            {
                // Log the method entry.
                Utilities.LogMessage(" Entry ", CoreConstants.Priority.Normal, CoreConstants.Category.General);

                //foreach (RowElement row in e.WorkBook.Worksheets[0].Table.Rows)
                //{
                //    row.Cells[0].StyleValue = "Style1";
                //}

                StyleElement style = new StyleElement("Style1");
                style.InteriorStyle.Pattern = InteriorPatternType.Solid;
                style.InteriorStyle.Color = System.Drawing.Color.LightGray;
                e.WorkBook.Styles.Add(style);

                // Log the method exit.
                Utilities.LogMessage(" Exit ", CoreConstants.Priority.Normal, CoreConstants.Category.General);
            }
            catch (UserInterfaceException exception)
            {
                // Log the error message to BizAgi DB.
                Utilities.LogMessage(exception.ToString(), CoreConstants.Priority.High, CoreConstants.Category.Trace);

                // Log the error message to SharePoint.
                Utilities.LogMessageToSharePoint(exception.ToString(),
                    CoreConstants.Priority.High, CoreConstants.Category.Trace);
            }
        }

        /// <summary>
        /// Binds childs rows to the Dashboard grid.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void RadGrid1_DetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e)
        {
            DateTime dateTimeDTB = System.DateTime.Now;
            gridLog.LogMsgToFile("___________ DetailTableDataBind Start___________");

            try
            {
                // Log the method entry.
                Utilities.LogMessage(" Entry ", CoreConstants.Priority.Normal, CoreConstants.Category.General);

                // Initialize DataController object.
                DataController dataController = new DataController();

                // Get the ParentKeyDataItem of requeired detailtable.
                GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem;

                // Get the CaseID value of ParentKeyDataItem.
                int caseID = Convert.ToInt32(dataItem.GetDataKeyValue("CaseID"));

                // If user click on teamleader/teammember user filter query on respective StatusKey.
                if (Session["gridFilter"] != null)
                    e.DetailTableView.DataSource = dataController.GetRequests("SELECT * FROM ProcessParams WHERE ParentCaseID = " + caseID + " AND StatusKey='" + Session["gridFilter"].ToString() + "'","detail");
                else
                    e.DetailTableView.DataSource = dataController.GetRequests("SELECT * FROM ProcessParams WHERE ParentCaseID = " + caseID,"detail");
        
                // Log the method exit.
                Utilities.LogMessage(" Exit ", CoreConstants.Priority.Normal, CoreConstants.Category.General);

            }
            catch (UserInterfaceException exception)
            {
                // Log the error message to BizAgi DB.
                Utilities.LogMessage(exception.ToString(), CoreConstants.Priority.High, CoreConstants.Category.Trace);

                // Log the error message to SharePoint.
                Utilities.LogMessageToSharePoint(exception.ToString(),
                    CoreConstants.Priority.High, CoreConstants.Category.Trace);
            }
            gridLog.LogMsgToFile("___________ DetailTableDataBind End___________ Time Taken:" + (System.DateTime.Now - dateTimeDTB).ToString() + " ms");
            
        }

        /// <summary>
        /// Binds requests data to Dashboard grid
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void RadGrid1_PreRender(object sender, EventArgs e)
        {
            DateTime dateTimePR = System.DateTime.Now;
            gridLog.LogMsgToFile("___________ PreRender Start___________");
            // Initiate business logic object.
            BLLController bllController = new BLLController();

            // dtGrid DataTable object to store requests data.
            DataTable dtGrid = new DataTable();

            // Initialize userName string variable to store userName session value.
            string userName = string.Empty;

            // Initialize userRoles string variable to stroe userRoles session value.
            string userRoles = string.Empty;

            // Initialize userReq string variable to store gridFilter session value.
            string userReq = string.Empty;
            int i = 0;
            try
            {
                // Log the method entry.
                Utilities.LogMessage(" Entry ", CoreConstants.Priority.Normal, CoreConstants.Category.General);


                // Get userName session value if not null.
                if (Session["userName"] != null)
                {
                    userName = Session["userName"].ToString();
                }

                // Get userRole session value if not null.
                if (Session["userRoles"] != null)
                {
                    userRoles = Session["userRoles"].ToString();
                }

                // Get gridFilter session value if not null.
                if (Session["gridFilter"] != null)
                {
                    userReq = Session["gridFilter"].ToString();
                }

                if (userReq.ToLower().Contains("inprocess"))
                {
                    gridLog.LogMsgToFile("___________ InProcess Start___________"+System.DateTime.Now.ToString());
                    // map dtGrid with requests results datatable.
                    dtGrid = bllController.GetInProcessRequests("wijnemar", userRoles);

                    // Map MasterTable of RadGrid1 if the GridNeedDataSource is not from DetailTable.                    
                    RadGrid1.DataSource = dtGrid;
                    
                    // Display and hide columns as per request.
                    GridColumnsDisplay(false, true, true,false);
                    RadGrid1.DataBind();
                    gridLog.LogMsgToFile("___________ InProcess End___________" + System.DateTime.Now.ToString());
                }
                else if (string.IsNullOrEmpty(Convert.ToString(Session["gridFilter"])) || userReq.ToLower().Contains("waiting"))
                {
                    gridLog.LogMsgToFile("___________ waiting Start___________" + System.DateTime.Now.ToString());
                    // map dtGrid with requests results datatable.
                    dtGrid = bllController.GetWaitingForMyActionRequests("wijnemar");

                    // Map MasterTable of RadGrid1 if the GridNeedDataSource is not from DetailTable.

                    RadGrid1.DataSource = dtGrid;
                    // Display and hide columns as per request.
                    GridColumnsDisplay(false, true, false,true);
                    RadGrid1.DataBind();

                    //foreach (GridDataItem item in RadGrid1.Items)
                    //{
                    //    CheckBox box = (CheckBox)item.FindControl("cbDraft");
                    //    i++;
                    //    if (!item["StatusDescription"].ToString().ToLower().Contains("draft"))
                    //    {
                    //        //box.Visible = false;
                    //        item.FindControl("cbDraft").Visible = false;
                    //    }
                    //    //RadGrid1.MasterTableView.GetColumn("CheckBoxTemplate").item
                    //    //if (item is GridEditableItem)
                    //    //{
                    //    //    GridEditableItem editableItem = item as GridDataItem;
                    //    //    TableCell cell = (TableCell)editableItem["StatusDescription"];
                    //    //    if (cell.Text.ToLower() == "draft")
                    //    //    {
                    //    //        editableItem.Edit = true;
                    //    //    }
                    //    //}                        
                    //}
                    //RadGrid1.DataBind();
                    gridLog.LogMsgToFile("___________ waiting end___________" + System.DateTime.Now.ToString());
                }
                else if (userReq.ToLower().Contains("delegate"))
                {
                    gridLog.LogMsgToFile("___________ delegate Start___________" + System.DateTime.Now.ToString());
                    // map dtGrid with requests results datatable.
                    dtGrid = bllController.GetDelegateRequests("wijnemar");

                    // Map MasterTable of RadGrid1 if the GridNeedDataSource is not from DetailTable.

                    RadGrid1.DataSource = dtGrid;
                    // Display and hide columns as per request.
                    GridColumnsDisplay(false, true, true,false);
                    RadGrid1.DataBind();
                    gridLog.LogMsgToFile("___________ delegate end___________" + System.DateTime.Now.ToString());
                }
                else if (userReq.ToLower().Contains("closed"))
                {
                    gridLog.LogMsgToFile("___________ closed Start___________" + System.DateTime.Now.ToString());
                    // map dtGrid with requests results datatable.
                    dtGrid = bllController.GetClosedRequests("wijnemar", userRoles);

                    // Map MasterTable of RadGrid1 if the GridNeedDataSource is not from DetailTable.

                    RadGrid1.DataSource = dtGrid;
                    // Display and hide columns as per request.
                    GridColumnsDisplay(true, false, false,false);
                    RadGrid1.DataBind();
                    gridLog.LogMsgToFile("___________ closed end___________" + System.DateTime.Now.ToString());
                }

                // Log the method exit.
                Utilities.LogMessage(" Exit ", CoreConstants.Priority.Normal, CoreConstants.Category.General);
            }
            catch (UserInterfaceException exception)
            {
                // Log the error message to BizAgi DB.
                Utilities.LogMessage(exception.ToString(), CoreConstants.Priority.High, CoreConstants.Category.Trace);

                // Log the error message to SharePoint.
                Utilities.LogMessageToSharePoint(exception.ToString(),
                    CoreConstants.Priority.High, CoreConstants.Category.Trace);
            }
            gridLog.LogMsgToFile("___________ PreRender End___________ Time Taken:" + (System.DateTime.Now - dateTimePR).ToString() + " ms");
            
        }

        /// <summary>
        /// Displays and hides required columns of the Grid
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void GridColumnsDisplay(bool caseCompletionDate, bool lastActionDate, bool currentAssignee,bool checkBox)
        {
            DateTime dateTimeGCD = System.DateTime.Now;
            gridLog.LogMsgToFile("___________ GridColumnsDisplay Start___________");
            try
            {
                // Log the method entry.
                Utilities.LogMessage(" Entry ", CoreConstants.Priority.Normal, CoreConstants.Category.General);

                // Dispaly or hide CaseCompletionDate of MasterTable.
                RadGrid1.MasterTableView.GetColumn("CaseCompletionDate").Visible = caseCompletionDate;
                // Display or hide LastActionDate of MasterTable.
                RadGrid1.MasterTableView.GetColumn("LastActionDate").Visible = lastActionDate;
                // Display or hide CurrentAssginee of MasterTable.
                RadGrid1.MasterTableView.GetColumn("CurrentAssignee").Visible = currentAssignee;
                // Display or hide CheckBox of MasterTable.
                RadGrid1.MasterTableView.GetColumn("selectDraftReq").Visible = checkBox;
                // Dispaly or hide CaseCompletionDate of DetailTables.
                //RadGrid1.MasterTableView.DetailTables[0].GetColumn("CaseCompletionDate").Visible = caseCompletionDate;
                // Display or hide LastActionDate of DetailTables.
                //RadGrid1.MasterTableView.DetailTables[0].GetColumn("LastActionDate").Visible = lastActionDate;
                // Display or hide CurrentAssginee of DetailTables.
                //RadGrid1.MasterTableView.DetailTables[0].GetColumn("CurrentAssignee").Visible = currentAssignee;
                
                // Log the method exit.
                Utilities.LogMessage(" Exit ", CoreConstants.Priority.Normal, CoreConstants.Category.General);
            }
            catch (UserInterfaceException exception)
            {
                // Log the error message to BizAgi DB.
                Utilities.LogMessage(exception.ToString(), CoreConstants.Priority.High, CoreConstants.Category.Trace);

                // Log the error message to SharePoint.
                Utilities.LogMessageToSharePoint(exception.ToString(),
                    CoreConstants.Priority.High, CoreConstants.Category.Trace);
            }
            gridLog.LogMsgToFile("___________ GridColumnsDisplay End___________ Time Taken:" + (System.DateTime.Now - dateTimeGCD).ToString() + " ms");
            
        }

        protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
        {
            // DataController Object
            DataController dtController = new DataController();
            DataTable dtGridItem = null;
            string statusKey = string.Empty;
            CheckBox draftCheckBox = sender as CheckBox;

            if(draftCheckBox.Checked)
            {
                // Get Dashboard row
                GridDataItem draftRow = draftCheckBox.NamingContainer as GridDataItem;
                // CaseID value of selected row
                int caseID = Convert.ToInt32(draftRow.GetDataKeyValue("CaseID").ToString());
                if(caseID!=null)
                    dtGridItem = dtController.GetRequests("SELECT StatusKey FROM ProcessParams WHERE CaseID=" + caseID,"checkbox");
                if(dtGridItem!=null)
                {
                    statusKey = dtGridItem.Rows[0][0].ToString();
                    if (statusKey != null && statusKey.Equals("Draft"))
                        draftCheckBox.Checked = true;
                    else
                    {
                        //Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert('Hi')</SCRIPT>");
                        draftCheckBox.Checked = false;
                        draftCheckBox.Enabled = true;
                    }
                }
            }
        }       
                   
    }
}
 we are getting struck. So, kindly advice ASAP.





0
Kostadin
Telerik team
answered on 20 Oct 2014, 08:25 AM
Hello Rasheed,

Keep in mind that when using an advanced databinding through NeedDataSource event handler you should never call DataBind()method during the page live cycle. I noticed that you are assigning a new DataSource to the grid and call DataBind on PreRender event handler which is not supported scenario. If you need to rebind the grid you have to call Rebind() method which will fire NeedDataSource event handler where you could change the DataSource of the grid. I would recommend you to examine the following help article which elaborates more on using an advanced data binding.

Regards,
Kostadin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Rasheed
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Rasheed
Top achievements
Rank 1
Share this question
or