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

Please help. RadGrid OnInsertCommand, OnUpdateComand not firing.

3 Answers 118 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kris
Top achievements
Rank 1
Kris asked on 16 Jul 2012, 04:40 AM
Hi,

I have a RadGrid in UserControl and I am trying to perform basic Crud operation using Inline edit per this demo.http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/entityframeworkcrud/defaultcs.aspx . This functionality works in another page where we dont use usercontrol. Please help.

User Control.

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="FollowUp.ascx.cs"
    Inherits="MedAssets.AMS.Web.Controls.FollowUp" %>
  
  
      
<style type="text/css">
       .RemoveEdit
       {
            display:none !important;
           color:lightblue !important;
       }
   </style>
  
<ContentTemplate>
    <div class="formLayoutE" id="divStatus" runat="server" style="padding-left: 15px; padding-right: 5px; padding-top: 5px">
        <asp:Panel ID="pnlMain" runat="server" Height="95%" Width="70%">    
      
       
         <telerik:RadTabStrip ID="tbStripFollowUp" runat="server" MultiPageID="RadMultiPage1"  Skin="Vista"
                SelectedIndex="0" CssClass="tabStrip" CausesValidation="False"  OnTabClick="tbStripFollowUp_TabClick" 
                EnableViewState="False">
                <Tabs>
                    <telerik:RadTab Text="Current" SelectedCssClass="horizontalTabSelected" Selected="True">
                    </telerik:RadTab>
                    <telerik:RadTab Text="History" SelectedCssClass="horizontalTabSelected"  >
                    </telerik:RadTab>
                </Tabs>
            </telerik:RadTabStrip>
              
              
             <telerik:RadMultiPage ID="RadMultiPage1" runat="server" SelectedIndex="0" 
                CssClass="multiPage" align="left" Width="100%"
                   EnableViewState="false" >
                
                <telerik:RadPageView ID="RadPageView1" runat="server">
                    <h3 class="formLayoutE_functionsheader">Scheduler</h3><br /> <br/>    
                      
                  <telerik:RadGrid ID="grdFollowUpAlert" runat="server" AutoGenerateColumns="false"  Skin="Windows7" Width="640px" EnableViewState="True"  
        AllowAutomaticDeletes="False" AllowAutomaticInserts="False" AllowAutomaticUpdates="False"
        OnItemCommand="grdFollowUpAlert_ItemCommand"
        OnItemDataBound="grdFollowUpAlert_ItemDataBound"
        OnNeedDataSource="grdFollowUpAlert_NeedsDataSource"
        OnInsertCommand="grdFollowUpAlert_InsertCommand"
        OnUpdateCommand="grdFollowUpAlert_UpdateCommand" 
        OnDeleteCommand="grdFollowUpAlert_DeleteCommand"
        OnCancelCommand="grdFollowUpAlert_CancelCommand"
        <ValidationSettings ValidationGroup="GroupAlphaRange" />
        <MasterTableView DataKeyNames="Id" CommandItemDisplay="Top" EditMode="EditForms">
        <CommandItemSettings AddNewRecordText="Add FollowUp" />
            <Columns>
                
                
                    <telerik:GridBoundColumn  DataField="FollowUpDateTime"  HeaderStyle-Width="100px" HeaderText="FollowUp Date" UniqueName="FollowUpDateTime" DataFormatString="{0:MM/dd/yyyy hh:mm tt}" />              
                    <telerik:GridBoundColumn DataField="Reason" HeaderStyle-Width="140px" HeaderText="Reason" UniqueName="Reason" DefaultInsertValue=" " />    
                    <telerik:GridBoundColumn  DataField="Name"  UniqueName="Name" HeaderStyle-Width="100px" HeaderText="Activity" DefaultInsertValue=" "  />
                    <telerik:GridBoundColumn DataField="CreatedBy" HeaderStyle-Width="55px" UniqueName="CreatedBy" HeaderText="Created By" /> 
                    <telerik:GridButtonColumn ConfirmText="Delete this item?" ConfirmDialogType="RadWindow" UniqueName="DeleteImageButton" HeaderStyle-Width="15px"  
                        ConfirmTitle="Confirm Delete" ButtonType="ImageButton"  CommandName="Delete" />
                          <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditImageButton" HeaderStyle-Width="15px" />
                <telerik:GridBoundColumn DataField="Id" Visible="false" />
                    <telerik:GridBoundColumn DataField="AccountId" HeaderStyle-Width="2px" HeaderText="AccountId" UniqueName="AccountId" Visible="False" />  
                    <telerik:GridBoundColumn DataField="WorkflowActivitySpecTypeId" HeaderStyle-Width="2px" HeaderText="WorkflowActivitySpecTypeId" UniqueName="WorkflowActivitySpecTypeId" Visible="False" />  
            </Columns>
            <EditFormSettings EditFormType="Template" InsertCaption="Add Followup" CaptionFormatString="Edit Followup">
                <FormTemplate
                    <table>
                        <tr>
                            <td>Assign From:</td>
                            <td><telerik:RadComboBox runat="server" ID="dropdownActivity" OnInit="OnInit_dropdownActivity" AppendDataBoundItems="True"
                            /></td>
                            <td>
                                  
                                                              
                            </td>
                        </tr>
                         
                        <tr>
                            <td>FollowUP DateTime:</td>
                            <td><telerik:RadDateTimePicker ID="followUpStartDate" runat="server" AutoPostBack="false"   
                            TimeView-RenderDirection="Vertical" Width="200px" /></td>
                            <td>
                                <asp:RequiredFieldValidator ID="valfollowUpStartDate" runat="server"
                                    ControlToValidate="followUpStartDate"
                                    ValidationGroup="valGroup"
                                    EnableClientScript="false"
                                    SetFocusOnError="true"
                                    Text="FollowUp Date is required"
                                    Display="Dynamic" />
                                 <asp:CustomValidator ID="valCustomFollowUpDateEndDateTime" runat="server"
                                    ControlToValidate="followUpStartDate"
                                    ValidationGroup="valGroup"
                                    ValidateEmptyText="false"
                                    OnServerValidate="ValidateFollowUpDateTimes"
                                    Text="FollowUp Date shouuld be greater than current date" 
                                    Display="Dynamic" />        
                            </td>
                        </tr>
                         
                        <tr>
                            <td valign="top">Reason:</td>
                            <td colspan="3">
                                <telerik:RadTextBox id="txtReason" runat="server" MaxLength="200" Columns="40" TextMode="MultiLine" Rows="4"
                                    SelectionOnFocus="SelectAll"   Text='<%# Bind("Reason") %>'/>
                            </td>
                        </tr>
                           <tr>
                            <td valign="top">Task Complete?:</td>
                            <td colspan="3">
                                <asp:CheckBox id="cbxTaskComplete" runat="server" Text="Match on Task Complete" />
                            </td>
                        </tr>
                       <tr
                            <td colspan="3">
                                <asp:Button ID="btnSave" runat="server" 
                                    Text='<%# (Container is GridEditFormInsertItem) ? "Add" : "Update" %>'
                                    CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>' 
                                    ValidationGroup="valGroup" SkinID="Windows7">
                                </asp:Button>                                 
                                <asp:Button runat="server" ID="btnCancel" Text="Cancel" Width="75px" CommandName="Cancel" SkinID="Windows7" />
                            </td>
                        </tr>
                    </table>
                </FormTemplate>               
            </EditFormSettings>
            <NoRecordsTemplate>There are no Follow Up entries to display.</NoRecordsTemplate>
        </MasterTableView>
    </telerik:RadGrid>
  
                </telerik:RadPageView>
                <telerik:RadPageView ID="RadPageView2"  runat="server" CssClass="pageViewEducation">
                    <br/>
                   <h3 class="formLayoutE_functionsheader">Follow Up History</h3><br /> <br/>    
                  <telerik:RadGrid ID="grdFollowUpHistory" runat="server" CssClass="Grid" Width="90%" Height="90%"  OnNeedDataSource="grdFollowUpHistory_NeedsDataSource"
                  OnItemDataBound="grdFollowUpHistory_ItemDataBound"
                            Skin="Windows7" AutoGenerateColumns="false" GridLines="Vertical" AllowSorting="True" AllowPaging="True" >
                            <PagerStyle Mode="NextPrevAndNumeric" />
                              
                            <MasterTableView DataKeyNames="FollowupID">
                                <Columns>
                                  <telerik:GridBoundColumn  DataField="FollowUpDateTime"  HeaderStyle-Width="40px" HeaderText="FollowUp Date" UniqueName="FollowUpDateTime" DataFormatString="{0:MM/dd/yyyy hh:mm tt}" />              
                                  <telerik:GridBoundColumn DataField="Reason" HeaderStyle-Width="80px" HeaderText="Reason" UniqueName="Reason" DefaultInsertValue=" " />    
                                  <telerik:GridBoundColumn DataField="Name" HeaderStyle-Width="40px" UniqueName="Name" HeaderText="Activity" DefaultInsertValue=" "  />
                                  <telerik:GridBoundColumn DataField="CreatedBy" HeaderStyle-Width="40px" HeaderText="Created By" /> 
                                  <telerik:GridBoundColumn DataField="WorkflowActivitySpecTypeId" HeaderStyle-Width="2px" HeaderText="WorkflowActivitySpecTypeId" UniqueName="WorkflowActivitySpecTypeId" Visible="False" />
                                </Columns>
                            </MasterTableView>
                        </telerik:RadGrid>
                          
  
                </telerik:RadPageView>
                 
            </telerik:RadMultiPage>
  
  
  
  
  
</asp:Panel>
    </div>
      
</ContentTemplate>

CodeBehind
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using MedAssets.AAA;
using MedAssets.AMS.Business.Common;
using MedAssets.AMS.Business.WorkDistribution;
using MedAssets.AMS.Common;
using MedAssets.AMS.DataAccess;
using MedAssets.AMS.Web.Admin.WorkDistribution;
using MedAssets.AMS.Workflow;
using MedAssets.Aaa.Security;
using MedAssets.Aaa.TaskQueues;
using MedAssets.Aaa.Users;
using MedAssets.Log;
using MedAssets.AMS.Workflow;
  
using StructureMap;
  
using Telerik.Web.UI;
  
namespace MedAssets.AMS.Web.Controls
{
  
    public partial class FollowUp : BaseWorkflowControl 
    {
          
  
        private const string mTimeZoneCookieName = "TZOS"; // Time zone Offset
        private IWorkFollowup iWorkFollowup = new WorkFollowup();
        private IWorkflow m_workflow;
        public IWorkflow Workflow
        {
            get
            {
                var workflow = m_workflow ?? (m_workflow = WorkflowService.GetActiveWorkflowForAccount(AccountADT.Account.Id));
                return workflow ?? (new Workflow.Workflow(new WorkflowKey(AccountADT.Account.FacilityId, Guid.NewGuid())) { AccountId = AccountADT.AccountId });
            }
            set { m_workflow = value; }
        }
  
  
       private CultureInfo enUS = new CultureInfo("en-US"); 
        private int? activitySpecTypeId;
        private DateTime followUpDate;
        private Boolean isComplete = false;
        private string reason = string.Empty;
        private Guid followUpId;
  
        protected void OnPreInit(EventArgs e)
        {
            setCookieForTimezoneOffset();   
        }
        protected void Page_Load(object sender, EventArgs e)
        {
           
            if(!IsPostBack)
            {
                m_workflow = WorkflowService.GetActiveWorkflowForAccount(AccountADT.Account.Id);
                PopulateGrid("grdFollowUpAlert", true);
                PopulateGrid("grdFollowUpHistory", true);
               // RadScheduler1.TimeZoneOffset = new TimeSpan(getTimezoneOffset(), 0, 0);
                InitializeAppointments();
                 
            }
  
        }
        
  
        private static int GetEnumValue(Enum wfEnum )
        {
            return (int)Enum.Parse(wfEnum.GetType(), wfEnum.ToString());
        }
  
  
  
        private void InitializeAppointments()
        {
  
              
  
            //DateTime start = DateTime.UtcNow.Date;
            //start = start.AddHours(6);
            //Appointments.Add(new AppointmentInfo("Take the car to the service", start, start.AddHours(1), string.Empty, null, new Reminder(30).ToString(), 1));
            //Appointments.Add(new AppointmentInfo("Meeting with Alex", start.AddHours(2), start.AddHours(3), string.Empty, null, string.Empty, 2));
  
            //start = start.AddDays(-1);
            //DateTime dayStart = RadScheduler1.UtcDayStart(start);
            //Appointments.Add(new AppointmentInfo("Bob's Birthday", dayStart, dayStart.AddDays(1), string.Empty, null, string.Empty, 1));
            //Appointments.Add(new AppointmentInfo("Call Charlie about the Project", start.AddHours(2), start.AddHours(3), string.Empty, null, string.Empty, 2));
  
            //start = start.AddDays(2);
            //Appointments.Add(new AppointmentInfo("Get the car from the service", start.AddHours(2), start.AddHours(3), string.Empty, null, string.Empty, 1));
        }
  
  
        public override void Populate()
        {
              
        }
  
        private void PopulateGrid(string gridName, bool needRebind)
        {
            var cbo = (RadGrid)FindControlRecursive(Page, gridName);
            if (gridName == "grdFollowUpAlert")
            {
               
                //if(IsWorkFlowOverridden(Workflow))
                //{
                //    //var tbControl = (RadTab)FindControlRecursive(Page, "Current");
                //    //tbControl.Visible = false;
                //    return;
                //}
                if (cbo != null)
                {
                    cbo.DataSource = GetFollowUpDetails().Where(a => a.IsComplete == false);
                    
                      
                }
  
            }
  
            if (gridName == "grdFollowUpHistory")
            {
                if (cbo != null)
                {
                    cbo.DataSource = GetFollowUpDetails().Where(a => a.IsComplete == true);
                    if (needRebind) { cbo.Rebind(); }
                }
            }
             
        }
  
        private IEnumerable<WorkFollowup> GetFollowUpDetails()
        {
            return ObjectFactory.GetInstance<IWorkflowFollowupManager>().GetWorkflowFollowUp(AccountId, FacilityId);
        }
  
        private void SaveFollowUp(IWorkFollowup workfollowup)
        {
            ObjectFactory.GetInstance<IWorkflowFollowupManager>().Save(workfollowup);
        }
  
        private void DeleteFollowUp(Guid followUpId)
        {
            ObjectFactory.GetInstance<IWorkflowFollowupManager>().Delete(followUpId);
        }
  
  
  
        private void setCookieForTimezoneOffset()
        {
            if (Request.Cookies[mTimeZoneCookieName] == null)
            {
                Page.ClientScript.RegisterStartupScript(GetType(), "Timezone", 
                     string.Format
                     (  @"<script language=""javascript"">document.cookie = ""{0}="" + new Date().getTimezoneOffset(); </script>",  
                              mTimeZoneCookieName)); 
                  
            }  
        }
        public int TimezoneOffset
        {
            get
            {
               return getTimezoneOffset();  
            }  
        }  
          
        private int getTimezoneOffset() 
        {  
            int returnValue = (Request.Cookies[mTimeZoneCookieName] == null) ? 0 : Convert.ToInt32(Request.Cookies[mTimeZoneCookieName].Value); 
              
          // JavaScript returns 300 if the offset is -5 offset so I convert the number  
            return (returnValue / 60) * -1;   
        }
  
  
  
  
        private IWorkDistributionManager _workDistributionManager;
  
        private IWorkDistributionManager WorkDistributionManager
        {
            get
            {
                return _workDistributionManager ??
                       (_workDistributionManager = ObjectFactory.GetInstance<IWorkDistributionManager>());
            }
        }
  
        private IUserTreeManager _userTreeManager;
  
        private IUserTreeManager UserTreeManager
        {
            get { return _userTreeManager ?? (_userTreeManager = ObjectFactory.GetInstance<IUserTreeManager>()); }
        }
  
        private ITaskQueueImpersonation iTaskQueueImpersonation = new TaskQueueImpersonation();
       
  
        protected void grdFollowUpAlert_NeedsDataSource(object sender, GridNeedDataSourceEventArgs args)
        {
  
            PopulateGrid("grdFollowUpAlert", false);
        }
  
        protected void grdFollowUpHistory_NeedsDataSource(object sender, GridNeedDataSourceEventArgs args)
        {
  
            PopulateGrid("grdFollowUpHistory", false);
        }
        protected void grdFollowUpAlert_ItemCommand(object sender, GridCommandEventArgs e)
        {
            switch (e.CommandName)
            {
                //cancel default edit command and load the edited data in the external form
                case RadGrid.EditCommandName:
                    //iTaskQueueImpersonation = WorkDistributionManager.GetTaskQueueImpersonation(
                    //    (Guid)e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Id"]);
                    e.Item.OwnerTableView.IsItemInserted = false;
                    break;
                case RadGrid.InitInsertCommandName:
                    grdFollowUpAlert.MasterTableView.ClearEditItems();
                    break;
            }
             
        }
  
        protected void grdFollowUpAlert_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem)
            {
                  
            }
  
            if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
            {
                if (e.Item.OwnerTableView.IsItemInserted)
                {
                    var insertedItem = (GridEditFormItem)e.Item;
  
                    var ctlFollowUpStartDate = (RadDateTimePicker)insertedItem.FindControl("followUpStartDate");
                    ctlFollowUpStartDate.MinDate = DateTime.Today;
  
                }
                else
                {
                   iWorkFollowup  = (IWorkFollowup)e.Item.DataItem;
  
                    GridEditFormItem edititem = (GridEditFormItem)e.Item;
  
                    var ctldropdownActivity = (RadComboBox)edititem.FindControl("dropdownActivity");
  
                    RadComboBoxItem itemAc =
                        ctldropdownActivity.FindItemByValue(iWorkFollowup.WorkflowActivitySpecTypeId.ToString());
                    itemAc.Selected = true;
  
                    var minDate = iWorkFollowup.FollowupDateTime;
  
                    var ctlFollowUpDate = (RadDateTimePicker)edititem.FindControl("followUpStartDate");
                    ctlFollowUpDate.MinDate = minDate;
                    ctlFollowUpDate.DbSelectedDate = iTaskQueueImpersonation.StartDate.ToString();
  
                    var isComplete = (CheckBox)edititem.FindControl("cbxTaskComplete");
                    isComplete.Checked = iWorkFollowup.IsComplete;
                }
            }
  
            if (e.Item is GridDataItem)
            {
                GridDataItem ditem = (GridDataItem)e.Item;
  
                TableCell accountCell = (TableCell)ditem["AccountId"];
  
                if (IsWorkFlowOverriddenByAccountId(new Guid(accountCell.Text)))
                {
                    ditem.Display = false;
                }
                else
                {
                    //GridEditCommandColumn editcol = (GridEditCommandColumn)["EditImageButton"].Controls[0];
  
                    TableCell userCell = (TableCell) ditem["CreatedBy"];
                    if (userCell.Text != HttpContext.Current.User.Identity.Name)
                    {
                        var imgBtn = (ImageButton)ditem["DeleteImageButton"].Controls[0];
  
                        ditem["EditImageButton"].CssClass = "RemoveEdit"; 
                        var lnk = ditem["EditImageButton"].Controls[0] as LinkButton;
                        ditem["EditImageButton"].Controls.Remove(lnk);
                        imgBtn.Visible = false;
                        //editcol.Display = false;
                    }
  
                }
                TableCell specTypeId = (TableCell)ditem["WorkflowActivitySpecTypeId"];
                TableCell specTypeName = (TableCell)ditem["Name"];
                var en = (WorkflowActivitySpecType)Convert.ToInt32(specTypeId.Text);
                specTypeName.Text  = en.Description();
  
                TableCell followUpDateTime = (TableCell) ditem["FollowUpDateTime"];
  
                DateTime dt = DateTime.ParseExact(followUpDateTime.Text, "g", enUS, DateTimeStyles.None);
                //DateTime dt = DateTime.ParseExact(followUpDateTime.Text, "yyyyMMddHHmm", null);
                //DateTime loadedDate = DateTime.ParseExact(loadedString, "d", null);
  
                dt = dt.AddHours(TimezoneOffset);
  
                followUpDateTime.Text = dt.ToString();
  
                //if(!string.IsNullOrEmpty(specTypeId.Text))
                //{
                //    
                //    var wf = GetWorkFlowByAccountId(new Guid(accountCell.Text));
  
                //    var fid = new Guid("A73FC5C9-B2EC-4DE7-992C-07F38797CC9E");
                //    //var specTypeList =
                //    //    GetWorkFlowSpecByFacilityId(Workflow.FacilityId).Where(a => a.SpecType == en);
  
                //    var specTypeList =
                //     GetWorkFlowSpecByFacilityId(fid).Where(a => a.SpecType == en);
                //    foreach(var list in specTypeList )
                //    {
                //        foreach(var ts in list.TaskSpecList)
                //        {
                //            ts.WorkflowActivitySpecId = en;
                //        }
                //    }
  
                //    TableCell activitySpecTypeNameCell = (TableCell)ditem["Name"];
                //    activitySpecTypeNameCell.Text  = (specTypeList.Count() > 0)? specTypeList.FirstOrDefault().Name :string.Empty;
  
                //}
  
  
            }
        }
  
        protected void grdFollowUpHistory_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem ditem = (GridDataItem) e.Item;
  
                TableCell specTypeId = (TableCell) ditem["WorkflowActivitySpecTypeId"];
                TableCell specTypeName = (TableCell) ditem["Name"];
                var en = (WorkflowActivitySpecType) Convert.ToInt32(specTypeId.Text);
                specTypeName.Text = en.Description();
  
                TableCell followUpDateTime = (TableCell) ditem["FollowUpDateTime"];
  
                DateTime dt = DateTime.ParseExact(followUpDateTime.Text, "g", enUS, DateTimeStyles.None);
                //DateTime dt = DateTime.ParseExact(followUpDateTime.Text, "yyyyMMddHHmm", null);
                //DateTime loadedDate = DateTime.ParseExact(loadedString, "d", null);
  
                dt = dt.AddHours(TimezoneOffset);
  
                followUpDateTime.Text = dt.ToString();
            }
        }
        private static string GetDescription(Enum en)
        {
            Type type = en.GetType();
  
            MemberInfo[] memInfo = type.GetMember(en.ToString());
  
            if (memInfo != null && memInfo.Length > 0)
            {
                object[] attrs = memInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), false);
  
                if (attrs != null && attrs.Length > 0)
                {
                    return ((DescriptionAttribute)attrs[0]).Description;
                }
            }
  
            return en.ToString();
        }
        protected void grdFollowUpAlert_InsertCommand(object sender, GridCommandEventArgs e)
        {
            if (!Page.IsValid)
            {
                return;
            }
  
            //Get the GridEditFormInsertItem of the RadGrid 
            GridEditFormInsertItem insertedItem = (GridEditFormInsertItem)e.Item;
  
            //Access the textbox from the insert form template and store the values in variables. 
             var specType = (WorkflowActivitySpecType)System.Enum.Parse(typeof(WorkflowActivitySpecType), ((RadComboBox)insertedItem.FindControl("dropdownActivity")).SelectedItem.Text);
            var x = (int) specType;
            //activitySpecTypeId = ((RadComboBox)insertedItem.FindControl("dropdownActivity")).SelectedIndex > 0 ? 
            //    : null;
            //    Convert.ToInt32(((RadComboBox)insertedItem.FindControl("dropdownActivity")).SelectedItem.Value);
  
            followUpDate = (DateTime)((RadDateTimePicker)insertedItem.FindControl("followUpStartDate")).DbSelectedDate;
  
         
            var radReason = ((RadTextBox)insertedItem.FindControl("txtReason")).Text;
            if (radReason != string.Empty)
                reason = radReason;
  
            isComplete = ((CheckBox)insertedItem.FindControl("cbxTaskComplete")).Checked;
  
            followUpId = (Guid)e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Id"];
  
     
            IWorkFollowup iworkfollowup = new WorkFollowup(new WorkFollowupKey(Guid.NewGuid()));
            iworkfollowup = UpdateFollowUp(iworkfollowup, false);
              
            SaveFollowUp(iworkfollowup);
  
          }
  
        protected void grdFollowUpAlert_UpdateCommand(object sender, GridCommandEventArgs e)
        {
            if (!Page.IsValid)
            {
                return;
            }
  
            //Get the GridEditableItem of the RadGrid 
            GridEditableItem editedItem = e.Item as GridEditableItem;
  
            //Access the textbox from the edit form template and store the values in variables. 
            if (editedItem != null)
            {
                activitySpecTypeId =
                     Convert.ToInt32(((RadComboBox)editedItem.FindControl("dropdownActivity")).SelectedItem.Value);
  
                followUpDate = (DateTime)((RadDatePicker)editedItem.FindControl("followUpStartDate")).DbSelectedDate;
  
                
                var radReason = ((RadTextBox)editedItem.FindControl("txtReason")).Text;
                reason = radReason != string.Empty ? radReason : string.Empty;
  
                followUpId = (Guid)e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Id"];
  
                isComplete = ((CheckBox)editedItem.FindControl("cbxTaskComplete")).Checked;
  
                IWorkFollowup iworkfollowup = new WorkFollowup(new WorkFollowupKey(followUpId));
                iworkfollowup = UpdateFollowUp(iworkfollowup, false);
              
                SaveFollowUp(iworkfollowup);
  
            }
        }
        
  
        private IWorkFollowup UpdateFollowUp(IWorkFollowup workfollowup, bool isNew)
        {
  
            workfollowup.AccountId = AccountId;
            workfollowup.FacilityId = FacilityId;
            workfollowup.WorkflowActivitySpecTypeId = activitySpecTypeId;
            workfollowup.FacilityId = FacilityId;
            workfollowup.FollowupDateTime = followUpDate;
              
  
  
            if (isNew)
            {
                 
                if (reason != string.Empty)
                    workfollowup.Reason = reason;
                workfollowup.IsComplete = false;
                workfollowup.CreatedBy = HttpContext.Current.User.Identity.Name;
                workfollowup.CreatedOn = DateTime.Now;
                  
            }
            else
            {
  
                workfollowup.Reason = reason == string.Empty ? null : reason;
                workfollowup.IsComplete = isComplete;
                workfollowup.ModifiedBy = HttpContext.Current.User.Identity.Name;
                workfollowup.ModifiedOn = DateTime.Now;
                //workfollowup.FollowupId = followUpId;
            }
  
            return workfollowup;
        }
  
        protected void grdFollowUpAlert_DeleteCommand(object sender, GridCommandEventArgs e)
        {
            var id = (Guid)e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Id"];
  
            DeleteFollowUp(id);
              
        }
  
        protected void grdFollowUpAlert_CancelCommand(object sender, GridCommandEventArgs e)
        {
            //grdFollowUpAlert.Rebind();
        }
  
      
        protected void ValidateFollowUpDateTimes(object sender, ServerValidateEventArgs args)
        {
            var validator = (CustomValidator)sender;
            var editItem = (GridEditFormItem)validator.NamingContainer;
  
            var ctlfollowUpDate = (RadDateTimePicker)editItem.FindControl("followUpStartDate");
            var dbSelectedDate = ctlfollowUpDate.DbSelectedDate;
             
  
            var dateFollowUp = (DateTimeOffset?)((DateTime)dbSelectedDate);
  
            args.IsValid = dateFollowUp > DateTime.Now;
  
        }
  
        protected void OnInit_dropdownActivity(object sender, EventArgs e)
        {
            LoadDropdown();
        }
  
        
        private void LoadDropdown()
        {
             
           var cbo = (RadComboBox)FindControlRecursive(Page, "dropdownActivity");
             if (cbo != null)
            {
                cbo.Items.Clear();
  
                var enumList = Enum.GetValues(typeof(WorkflowActivitySpecType)).Cast<WorkflowActivitySpecType>().ToList();
                  
                cbo.DataSource = enumList;
                 //cbo.DataTextField = "Name";
                 //cbo.DataValueField = "WorkflowActivitySpecTypeId";
                cbo.DataBind();
                cbo.Items.Insert(0, new Telerik.Web.UI.RadComboBoxItem { Text = "--Select a Value--", Value = "--Select a Value--" });
                cbo.SelectedIndex = 0; 
                  
            }
        }
  
        public static Control FindControlRecursive(Control root, string id)
        {
            if (id == string.Empty)
                return null;
  
            if (root.ID == id)
                return root;
  
            foreach (Control c in root.Controls)
            {
                Control t = FindControlRecursive(c, id);
                if (t != null)
                {
                    return t;
                }
            }
            return null;
        }
  
        private bool IsWorkFlowOverridden(IWorkflow workflow)
        {
            var workflowStatus = workflow.WorkflowStatus;
            return (workflowStatus == WorkflowStatus.AutoAccountOverride ||
                    workflowStatus == WorkflowStatus.ManualAccountOverride);
        }
  
        private bool IsWorkFlowOverriddenByAccountId(Guid accountId)
        {
  
            var workflow = WorkflowService.GetActiveWorkflowForAccount(accountId) ??
                (new Workflow.Workflow(new WorkflowKey(AccountADT.Account.FacilityId, Guid.NewGuid())) { AccountId = accountId });
              
            var workflowStatus = workflow.WorkflowStatus;
            return (workflowStatus == WorkflowStatus.AutoAccountOverride ||
                    workflowStatus == WorkflowStatus.ManualAccountOverride);
        }
  
        private IWorkflow GetWorkFlowByAccountId(Guid accountId)
        {
  
            return WorkflowService.GetActiveWorkflowForAccount(accountId) ??
                (new Workflow.Workflow(new WorkflowKey(AccountADT.Account.FacilityId, Guid.NewGuid())) { AccountId = accountId });
  
            
        }
        private IEnumerable<IWorkflowActivitySpec> GetWorkFlowSpecByFacilityId(Guid facilityId)
        {
            return ObjectFactory.GetInstance<IWorkflowFollowupManager>().GetWorkflowSpecByFaclilityId(facilityId);
  
              
        }
  
        protected void tbStripFollowUp_TabClick(object sender, RadTabStripEventArgs e)
        {
           
        }
  
    }
}

3 Answers, 1 is accepted

Sort by
0
Kris
Top achievements
Rank 1
answered on 16 Jul 2012, 07:54 PM
Can anyone help?
0
Andrey
Telerik team
answered on 19 Jul 2012, 06:13 AM
Hello,

Which RadGrid does not fire the OnInsert and OnUpdateCommand events -- the grdFollowUpHistory or grdFollowUpAlert?

Additionally I noticed that you have some validator controls in the edit form, could you try to temporarily disable the validation and check whether the issue still replicates.


Kind regards,
Andrey
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Kris
Top achievements
Rank 1
answered on 19 Jul 2012, 01:12 PM
Thanks but since it has been more than five days, I have figured out the issue myself. Two things I did
1)EnableViewState at the Grid level. The parent page had Enableviewstate=false
2) I added RadAjaxProxyManager to Usercontrol.

Thanks

Kris
Tags
Grid
Asked by
Kris
Top achievements
Rank 1
Answers by
Kris
Top achievements
Rank 1
Andrey
Telerik team
Share this question
or