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

oldValues and newValues missing for RadComboBox in Template Fields

1 Answer 49 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 28 Aug 2014, 08:36 PM
I have a form with multiple RadComboBoxes in it.  There are populated by the NeedsDataSource option.  The grid is being edited using InLine batch updating.  When the item is saved, the hash values are missing for the combobox fields unless I have opened them once while editing the record.  It seems I need to have the all populate.  How can I do that?

ASPX
<%@ Page Title="" Language="C#"  MasterPageFile="~/Content/themes/Level_One.Master" AutoEventWireup="true" CodeBehind="RequestGridView.aspx.cs" Inherits="WebApplication.Forms.RequestGridView" %>
 
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%@ MasterType VirtualPath="~/Content/themes/Level_One.Master" %>
 
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link href="../Content/Styles.css" rel="Stylesheet" />
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">
            var radGridId = "<%=requests_grid.ClientID %>";
        </script>
    </telerik:RadCodeBlock>
    <%: System.Web.Optimization.Styles.Render("~/Content/css") %>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="main_placeholder" runat="server">
    <style type="text/css">
        html body span .rinSingle .riTextBox RadInput .RadInput_Default
        {
            width: 100% !important;
        }
 
    </style>
   <telerik:RadCodeBlock ID="cb1" runat="server">
        <script type="text/javascript">
            function mngRequestStarted(ajaxManager, eventArgs) {
                // alert(eventArgs.get_eventTargetElement())
                var newArr = new Array();
                for (var name in ajaxManager) {
                    newArr.push(name + "<-->" + ajaxManager[name])
 
                }
            }
 
        </script>
    </telerik:RadCodeBlock>
 
    <telerik:RadScriptManager ID="main_radscriptmanager" runat="server" EnableViewState="true">
        <Scripts>
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
        </Scripts>
    </telerik:RadScriptManager>
    <telerik:RadAjaxLoadingPanel ID="main_loading" runat="server" Skin="Metro" EnableViewState="true"></telerik:RadAjaxLoadingPanel>
    <telerik:RadScriptBlock runat="server" ID="RadScriptBlock2">
<%--        <script type="text/javascript">
 
            function RowContextMenu(sender, eventArgs) {
                var menu = $find("<%=RadMenu1.ClientID %>");
                var evt = eventArgs.get_domEvent();
                var index = eventArgs.get_gridDataItem().get_element().id.split("__")[1];
                document.getElementById("<%=radGridClickedRowIndex.ClientID %>").value = index;
                sender.get_masterTableView().selectItem(sender.get_masterTableView().get_dataItems()[index].get_element(), true);
                menu.show(evt);
                evt.cancelBubble = true;
                evt.returnValue = false;
                if (evt.stopPropagation) {
                    evt.stopPropagation();
                    evt.preventDefault();
                }
            }
        </script>--%>
    </telerik:RadScriptBlock>
    <%--<asp:HiddenField ID="radGridClickedRowIndex" runat="server" />--%>
 
    <telerik:RadAjaxManager ID="main_ajaxmanager" runat="server" EnableAJAX="true" EnableViewState="true" ClientEvents-OnRequestStart="mngRequestStarted">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="requests_grid">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="requests_grid" LoadingPanelID="main_loading" />
                    <telerik:AjaxUpdatedControl ControlID="requests_grid" UpdatePanelHeight="100%" />
                </UpdatedControls>
            </telerik:AjaxSetting>
 
            <telerik:AjaxSetting AjaxControlID="main_windowmanager">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="main_windowmanager" LoadingPanelID="main_loading" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
 
    <telerik:RadGrid ID="requests_grid" runat="server"
        Height="100%"
        Skin="Metro"
        EnableViewState="true"
        AutoGenerateColumns="false"
        ShowFooter="false"
        AllowSorting="true"
        CommandItemDisplay="Top"
        AllowFilteringByColumn="False"
        AllowAutomaticUpdates="True"
        OnNeedDataSource="requests_grid_NeedDataSource"
        OnBatchEditCommand="requests_grid_BatchEditCommand"
        OnItemCommand="requests_grid_ItemCommand"
        OnItemDataBound="requests_grid_ItemDataBound">
        <MasterTableView AutoGenerateColumns="false" DataKeyNames="RequestId" CommandItemDisplay="Top" EditMode="Batch">
            <BatchEditingSettings EditType="Row" OpenEditingEvent="Click" />
            <ColumnGroups>
                <telerik:GridColumnGroup HeaderText="Estimates" Name="Estimates" HeaderStyle-HorizontalAlign="Center"></telerik:GridColumnGroup>
                <telerik:GridColumnGroup HeaderText="Actuals" Name="Actuals" HeaderStyle-HorizontalAlign="Center"></telerik:GridColumnGroup>
                <telerik:GridColumnGroup HeaderText="Function Owner" Name="FunctionOwner" HeaderStyle-HorizontalAlign="Center"></telerik:GridColumnGroup>
            </ColumnGroups>
            <Columns>
                <telerik:GridBoundColumn DataField="RequestId"
                    HeaderText="ID"
                    HeaderStyle-Width="50px"
                    ReadOnly="true">
                    <ItemStyle HorizontalAlign="Center" />
                </telerik:GridBoundColumn>
                <%--<telerik:GridBoundColumn DataField="RequestTitle"
                    HeaderStyle-Width="250px"
                    HeaderText="Request Title"
                    UniqueName="RequestTitle">
                    <ItemStyle Width="100%" />
                </telerik:GridBoundColumn>--%>
                <telerik:GridTemplateColumn HeaderText="Request Title"
                    HeaderStyle-Width="250px"
                    UniqueName="RequestTitle"
                    DataField="RequestTitle">
                    <ItemTemplate>
                        <%# Eval("RequestTitle") %>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadTextBox runat="server"
                            ID="txtRequestTitle" Width="100%" TextMode="MultiLine" Rows="3" Wrap="true">
                        </telerik:RadTextBox>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn HeaderText="Function Tool"
                    HeaderStyle-Width="200px"
                    UniqueName="FunctionToolId"
                    DataField="FunctionToolId">
                    <ItemTemplate>
                        <%# Eval("FunctionFunctionToolName") %>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadComboBox runat="server" ID="cboFunctionTool"
                            EnableLoadOnDemand="true"
                            Width="100%"
                            MarkFirstMatch="true"
                            OnItemsRequested="cboFunctionTool_ItemsRequested">
                        </telerik:RadComboBox>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn HeaderText="Category"
                    HeaderStyle-Width="100px"
                    UniqueName="RequestTypeId"
                    DataField="RequestTypeId">
                    <ItemTemplate>
                        <%# Eval("RequestTypeName") %>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadComboBox runat="server" ID="cboRequestType"
                            EnableLoadOnDemand="true"
                            Width="100%"
                            MarkFirstMatch="true"
                            OnItemsRequested="cboRequestType_ItemsRequested">
                        </telerik:RadComboBox>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn HeaderText="Priority"
                    HeaderStyle-Width="100px"
                    UniqueName="PriorityId"
                    DataField="PriorityId">
                    <ItemTemplate>
                        <%# Eval("PriorityName") %>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadComboBox runat="server" ID="cboPriority"
                            EnableLoadOnDemand="true"
                            Width="100%"
                            MarkFirstMatch="true"
                            OnItemsRequested="cboPriority_ItemsRequested">
                        </telerik:RadComboBox>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn HeaderText="Status"
                    HeaderStyle-Width="200px"
                    UniqueName="RequestStatusId"
                    DataField="RequestStatusId">
                    <ItemTemplate>
                        <%# Eval("RequestStatus") %>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadComboBox runat="server" ID="cboStatus"
                            EnableLoadOnDemand="true"
                            Width="100%"
                            MarkFirstMatch="true"
                            OnItemsRequested="cboStatus_ItemsRequested">
                        </telerik:RadComboBox>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn HeaderText="Assigned To"
                    HeaderStyle-Width="200px"
                    UniqueName="AssignedTo"
                    DataField="AssignedTo">
                    <ItemTemplate>
                        <%# Eval("Assignee") %>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadComboBox runat="server" ID="cboAssignedTo"
                            EnableLoadOnDemand="true"
                            Width="100%"
                            MarkFirstMatch="true"
                            OnItemsRequested="cboAssignedTo_ItemsRequested">
                        </telerik:RadComboBox>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn HeaderText="Requested By"
                    HeaderStyle-Width="200px"
                    UniqueName="RequestedBy"
                    DataField="RequestedBy">
                    <ItemTemplate>
                        <%# Eval("RequestedByName") %>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadComboBox runat="server" ID="cboRequestedBy"
                            EnableLoadOnDemand="true"
                            Width="100%"
                            MarkFirstMatch="true"
                            OnItemsRequested="cboRequestedBy_ItemsRequested">
                        </telerik:RadComboBox>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn HeaderText="Division"
                    HeaderStyle-Width="200px"
                    UniqueName="DivisionId"
                    DataField="DivisionId">
                    <ItemTemplate>
                        <%# Eval("DivisionName") %>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadComboBox runat="server" ID="cboDivision"
                            EnableLoadOnDemand="true"
                            Width="100%"
                            MarkFirstMatch="true"
                            OnItemsRequested="cboDivision_ItemsRequested">
                        </telerik:RadComboBox>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn HeaderText="Sequence"
                    HeaderStyle-Width="90px"
                    UniqueName="Sequence"
                    DataField="Sequence">
                    <ItemTemplate>
                        <%# Eval("Sequence") %>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadNumericTextBox ID="Sequence" runat="server" Type="Number"
                            EnabledStyle-HorizontalAlign="Right"
                            Width="100%">
                            <NumberFormat DecimalDigits="0" />
                        </telerik:RadNumericTextBox>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn HeaderText="Site"
                    HeaderStyle-Width="200px"
                    UniqueName="SiteId"
                    DataField="SiteId">
                    <ItemTemplate>
                        <%# Eval("SiteName") %>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadComboBox runat="server" ID="cboSite"
                            EnableLoadOnDemand="true"
                            Width="100%"
                            MarkFirstMatch="true"
                            OnItemsRequested="cboSite_ItemsRequested">
                        </telerik:RadComboBox>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn HeaderText="New Comment"
                    HeaderStyle-Width="250px"
                    UniqueName="Comments">
                    <ItemTemplate>
                         
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadTextBox runat="server"
                            ID="txtNewComment" Width="100%" TextMode="MultiLine" Rows="3" Wrap="true">
                        </telerik:RadTextBox>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn HeaderText="Start Date"
                    HeaderStyle-Width="100px"
                    UniqueName="EstimatedStartDate"
                    DataField="EstimatedStartDate"
                    ColumnGroupName="Estimates">
                    <ItemTemplate>
                        <%# Eval("EstimatedStartDate", "{mm/dd/yy}") %>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadDatePicker ID="dpEstimatedStartDate" runat="server"
                            Width="100%">
                        </telerik:RadDatePicker>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn HeaderText="Completion Date"
                    HeaderStyle-Width="100px"
                    UniqueName="EstimatedCompletionDate"
                    DataField="EstimatedCompletionDate"
                    ColumnGroupName="Estimates">
                    <ItemTemplate>
                        <%# Eval("EstimatedStartDate", "{mm/dd/yy}") %>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadDatePicker ID="dpEstimatedCompletionDate" runat="server"
                            Width="100%">
                        </telerik:RadDatePicker>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn HeaderText="Hours"
                    HeaderStyle-Width="90px"
                    UniqueName="EstimatedHours"
                    DataField="EstimatedHours"
                    ColumnGroupName="Estimates">
                    <ItemStyle HorizontalAlign="Right" />
                    <ItemTemplate>
                        <%# Eval("EstimatedHours") %>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadNumericTextBox ID="txtEstimatedHours" runat="server"
                            Width="100%"
                            EnabledStyle-HorizontalAlign="Right">
                            <NumberFormat DecimalDigits="2" />
                        </telerik:RadNumericTextBox>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn HeaderText="Start Date"
                    HeaderStyle-Width="100px"
                    UniqueName="ActualStartDate"
                    DataField="ActualStartDate"
                    ColumnGroupName="Actuals">
                    <ItemTemplate>
                        <%# Eval("ActualStartDate", "{mm/dd/yy}") %>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadDatePicker ID="dpActualStartDate" runat="server"
                            Width="100%">
                        </telerik:RadDatePicker>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn HeaderText="Hours"
                    HeaderStyle-Width="90px"
                    UniqueName="ActualHours"
                    DataField="ActualHours"
                    ColumnGroupName="Actuals">
                    <ItemStyle HorizontalAlign="Right" />
                    <ItemTemplate>
                        <%# Eval("ActualHours") %>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadNumericTextBox ID="txtActualHours" runat="server"
                            Width="100%"
                            EnabledStyle-HorizontalAlign="Right">
                            <NumberFormat DecimalDigits="2" />
                        </telerik:RadNumericTextBox>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn HeaderText="Date Closed"
                    HeaderStyle-Width="100px"
                    UniqueName="ClosingDate"
                    DataField="ClosingDate"
                    ColumnGroupName="Actuals">
                    <ItemTemplate>
                        <%# Eval("ClosingDate", "{mm/dd/yy}") %>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadDatePicker ID="dpClosingDate" runat="server"
                            Width="100%">
                        </telerik:RadDatePicker>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn HeaderText="Fixed Costs"
                    HeaderStyle-Width="90px"
                    UniqueName="FixedCosts"
                    DataField="FixedCosts">
                    <ItemTemplate>
                        <%# Eval("FixedCosts") %>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadNumericTextBox ID="txtFixedCosts" runat="server"
                            EnabledStyle-HorizontalAlign="Right"
                            Type="Number"
                            Width="100%">
                            <NumberFormat DecimalDigits="0" />
                        </telerik:RadNumericTextBox>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridBoundColumn DataField="CreatedOn"
                    HeaderText="Created"
                    DataFormatString="{0:d}"
                    HeaderStyle-Width="100px"
                    HeaderStyle-HorizontalAlign="Center"
                    ItemStyle-HorizontalAlign="Right"
                    ReadOnly="true">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="CreatedByName"
                    HeaderText="Created By"
                    HeaderStyle-Width="120px"
                    ReadOnly="true">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="UpdatedOn"
                    HeaderText="Updated"
                    DataFormatString="{0:d}"
                    HeaderStyle-Width="100px"
                    HeaderStyle-HorizontalAlign="Center"
                    ItemStyle-HorizontalAlign="Right"
                    ReadOnly="true">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="UpdatedByName"
                    HeaderText="Updated By"
                    HeaderStyle-Width="120px"
                    ReadOnly="true">
                </telerik:GridBoundColumn>
 
            </Columns>
        </MasterTableView>
        <ClientSettings AllowColumnsReorder="true" AllowKeyboardNavigation="true">
            <Scrolling AllowScroll="true" UseStaticHeaders="true" FrozenColumnsCount="1" />
        </ClientSettings>
    </telerik:RadGrid>
 
    <telerik:RadWindowManager runat="server" ID="main_windowmanager" EnableViewState="true"></telerik:RadWindowManager>
 
</asp:Content>


C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Core;
using DataEntities.Application.Context;
using DataEntities.Application.Entities;
using Telerik.Web.UI;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
 
 
namespace Jabil.WebApplication.Forms
{
    public partial class RequestGridView : FrameworkPage
    {
 
        private class FilterOptions
        {
            int _FunctionId = -1;
            int _FunctionToolId = -1;
            bool _Closed = false;
 
            public int FunctionId
            {
                get
                { return _FunctionId; }
                set
                { _FunctionId = value; }
            }
            public int FunctionToolId
            {
                get
                { return _FunctionToolId; }
                set
                { _FunctionToolId = value; }
            }
            public bool Closed
            {
                get
                { return _Closed; }
                set
                { _Closed = value; }
            }
        }
 
        private FilterOptions filters = new FilterOptions();
 
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Master.PageTitle = "";
 
            if (!IsPostBack)
            {
                if (Request.QueryString["FunctionId"] != null)
                {
                    filters.FunctionId = Convert.ToInt32(Request.QueryString["FunctionId"].ToString());
                }
                if (Request.QueryString["FunctionToolId"] != null)
                {
                    filters.FunctionToolId = Convert.ToInt32(Request.QueryString["FunctionToolId"].ToString());
                }
                if (Request.QueryString["Closed"] != null)
                {
                    filters.Closed = Convert.ToBoolean(Request.QueryString["Closed"].ToString());
                }
 
                Session["Filters"] = filters;
            }
            else
            {
                if ((Session["Filters"] == null) == false)
                {
                    filters = (FilterOptions)Session["Filters"];
                }
 
            }
        }
 
 
        private void show_error_message(string error_message)
        {
            string error = error_message.Replace("'", "");
 
            main_ajaxmanager.ResponseScripts.Add(string.Format("window.radalert(\"" + error + "\")"));
        }
 
        protected void requests_grid_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            try
            {
                using (RequestsDataContext sdc = new RequestsDataContext(string.Empty))
                {
                    this.requests_grid.DataSource = sdc.GetRequestDetail(-1, filters.FunctionId, filters.FunctionToolId, filters.Closed).ToList<Request>();
                }
            }
            catch (Exception ex)
            {
                LogError(ex);
                show_error_message(ex.Message);
            }
 
        }
 
        private void SaveRequest(GridBatchEditingCommand grdItem)
        {
 
            Hashtable newValues = grdItem.NewValues;
            Hashtable oldValues = grdItem.OldValues;
            int RequestId = 0;
            if (grdItem.Type == GridBatchEditingCommandType.Update)
            {
                RequestId = (string.IsNullOrEmpty(grdItem.Item.GetDataKeyValue("RequestId").ToString())) ? 0 : Convert.ToInt32(grdItem.Item.GetDataKeyValue("RequestId").ToString());
            }
            //cbo = (RadComboBox)grdItem.FindControl("cboSite");
            int SiteId = 0;
            if (!string.IsNullOrEmpty(newValues["SiteId"].ToString()))
            {
                SiteId = Convert.ToInt32(newValues["SiteId"].ToString());//Convert.ToInt32(cbo.SelectedValue.ToString());
            }
            //cbo = (RadComboBox)grdItem.FindControl("cboStatus");
            int RequestStatusId = Convert.ToInt32(newValues["RequestStatusId"].ToString());//Convert.ToInt32(cbo.SelectedValue.ToString());
 
            //cbo = (RadComboBox)grdItem.FindControl("cboFunctionTool");
            int FunctionToolId = Convert.ToInt32(newValues["FunctionToolId"].ToString());//Convert.ToInt32(cbo.SelectedValue.ToString());
 
            //cbo = (RadComboBox)grdItem.FindControl("cboPriority");
            int PriorityId = Convert.ToInt32(newValues["PriorityId"].ToString());//Convert.ToInt32(cbo.SelectedValue.ToString());
 
            //cbo = (RadComboBox)grdItem.FindControl("cboRequestType");
            int RequestTypeId = Convert.ToInt32(newValues["RequestTypeId"].ToString());//Convert.ToInt32(cbo.SelectedValue.ToString());
 
            //txtBox = (RadTextBox)grdItem.FindControl("txtRequestTitle");
            string RequestTitle = newValues["RequestTitle"].ToString();//txtBox.Text.ToString();
 
            //cbo = (RadComboBox)grdItem.FindControl("cboAssignedTo");
            //dte =(RadDatePicker)grdItem.FindControl("dpEstimatedStartDate");
            Nullable<int> AssignedTo;
            if (string.IsNullOrEmpty(newValues["AssignedTo"].ToString()))
            {
                AssignedTo = null;
            }
            else
            {
                AssignedTo = Convert.ToInt32(newValues["AssignedTo"].ToString());
                //AssignationDate=(string.IsNullOrEmpty(dte.DateInput.SelectedDate.ToString())) ? DateTime.Today : dte.DateInput.SelectedDate;
            }
 
            Nullable<DateTime> ClosingDate = null;
 
            //ntxtBox = (RadNumericTextBox)grdItem.FindControl("Sequence");
            int Sequence = Convert.ToInt32(newValues["Sequence"].ToString());//Convert.ToInt32(ntxtBox.Text.ToString());
 
            //ntxtBox = (RadNumericTextBox)grdItem.FindControl("txtEstimatedHours");
            double EstimatedHours = string.IsNullOrEmpty(newValues["EstimatedHours"].ToString()) ? 0 : Convert.ToDouble(newValues["EstimatedHours"].ToString());
 
            //dte =(RadDatePicker)grdItem.FindControl("dpEstimatedStartDate");
            Nullable<DateTime> EstimatedStartDate =  null;
            if (!string.IsNullOrEmpty(newValues["EstimatedStartDate"].ToString()))
            {
                EstimatedStartDate =  Convert.ToDateTime(newValues["EstimatedStartDate"].ToString());// dte.DateInput.SelectedDate;
            }
 
            //dte =(RadDatePicker)grdItem.FindControl("dpEstimatedStartDate");
            Nullable<DateTime> EstimatedCompletionDate = null;
            if (!string.IsNullOrEmpty(newValues["EstimatedCompletionDate"].ToString()))
            {
                EstimatedCompletionDate = Convert.ToDateTime(newValues["EstimatedCompletionDate"].ToString());//dte.DateInput.SelectedDate;
            }
            //ntxtBox = (RadNumericTextBox)grdItem.FindControl("txtActualHours");
            double ActualHours = string.IsNullOrEmpty(newValues["ActualHours"].ToString()) ? 0 : Convert.ToDouble(newValues["ActualHours"].ToString());
 
            //dte =(RadDatePicker)grdItem.FindControl("dpActualStartDate");
            Nullable<DateTime> ActualStartDate = null;
            if (!string.IsNullOrEmpty(newValues["ActualStartDate"].ToString()))
            {
                ActualStartDate = Convert.ToDateTime(newValues["ActualStartDate"].ToString());//dte.DateInput.SelectedDate;
            }
 
            //ntxtBox = (RadNumericTextBox)grdItem.FindControl("txtFixedCosts");
            double FixedCosts = string.IsNullOrEmpty(newValues["FixedCosts"].ToString()) ? 0 : Convert.ToDouble(newValues["FixedCosts"].ToString());
 
            //cbo = (RadComboBox)grdItem.FindControl("cboDivision");
            int DivisionId = -1;
            if (!string.IsNullOrEmpty(newValues["DivisionId"].ToString()))
            {
                DivisionId = Convert.ToInt32(newValues["DivisionId"].ToString());//Convert.ToInt32(cbo.SelectedValue.ToString());
            }
            int ParentRequestId = 0;
 
            int UpdatedBy = (this.User as FrameworkPrincipal).UserId;
            int RequestedBy = (this.User as FrameworkPrincipal).UserId;
            bool IsAvailable = true;
 
            //txtBox = (RadTextBox)grdItem.FindControl("txtNewComment");
            string Comments = newValues["Comments"].ToString();//txtBox.Text.ToString();
 
            int NewRequestId = 0;
            using (RequestsDataContext rdc = new RequestsDataContext(string.Empty))
            {
                int result = rdc.UpdateRequest(RequestId, SiteId, RequestStatusId, FunctionToolId, PriorityId,
                    RequestTypeId, RequestTitle, AssignedTo,  ClosingDate, Sequence, EstimatedHours,
                    EstimatedStartDate, EstimatedCompletionDate, ActualHours, ActualStartDate, FixedCosts, DivisionId,
                    ParentRequestId, RequestedBy, UpdatedBy, IsAvailable, ref NewRequestId);
                if (NewRequestId != 0)
                {
                    //Save comment with new id
                    if (!string.IsNullOrEmpty(Comments))
                    {
 
                        result = rdc.UpdateRequestNote(0, NewRequestId, Comments, UpdatedBy);
                    }
 
                    //foreach (UploadedFile file in this.AsyncUpload.UploadedFiles)
                    //{
                    //    string fileName = file.FileName;
                    //    string fileExtension = file.GetExtension();
                    //    string contentType = file.ContentType;
                    //    byte[] fileContent = new byte[file.InputStream.Length];
                    //    using (Stream str = file.InputStream)
                    //        str.Read(fileContent, 0, (int)file.ContentLength);
 
                    //    result = rdc.UpdateSupportFile(0, NewRequestId, fileName, contentType, fileContent, UpdatedBy, true);
                    //}
                    this.requests_grid.Rebind();
                }
            }
        }
         
        protected void requests_grid_BatchEditCommand(object sender, Telerik.Web.UI.GridBatchEditingEventArgs e)
        {
            try
            {
                GridDataItem grdItem;
 
                 
                foreach (GridBatchEditingCommand command in e.Commands)
                {
 
                    grdItem = command.Item;
 
                    if (command.Type == GridBatchEditingCommandType.Update || command.Type == GridBatchEditingCommandType.Insert)
                    {
                        SaveRequest(command);
                    }
                    //switch (command.Type)
                    //{
                    //    case GridBatchEditingCommandType.Update:
                    //        SaveRequest(command);
                    //        break;
                    //    //case GridBatchEditingCommandType.Delete:
                    //    //    BenchmarkID = Convert.ToInt32(grdItem.GetDataKeyValue("BenchmarkGroupID"));
                    //    //    DeleteBenchmarkGroup(BenchmarkID);
                    //    //    break;
                    //    case GridBatchEditingCommandType.Insert:
                    //        SaveRequest(command);
                    //        break;
                    //}
                }
            }
            catch (Exception ex)
            {
                LogError(ex);
                show_error_message(ex.Message);
            }
        }
 
        protected void requests_grid_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
        {
            switch (e.CommandName)
            {
            }
 
        }
 
        protected void requests_grid_ItemDataBound(object sender, GridItemEventArgs e)
        {
            try
            {
                if (e.Item is GridEditableItem && e.Item.IsInEditMode)
                {
                    GridEditableItem editedItem = e.Item as GridEditableItem;
 
                    RadComboBox ddlFunctionTool = (RadComboBox)editedItem.FindControl("cboFunctionTool");
                    using (FunctionDataContext sdc = new FunctionDataContext(string.Empty))
                    {
                        foreach (Function_FunctionToolCBO this_item in sdc.GetFunction_FunctionToolList().ToList<Function_FunctionToolCBO>())
                        {
                            ddlFunctionTool.Items.Add(new Telerik.Web.UI.RadComboBoxItem(this_item.FunctionToolName.ToString(), this_item.FunctionToolId.ToString()));
                        }
 
                    }
                }
 
                if (e.Item is GridDataItem)
                {
                    //Put all data items in Edit. We will need to call Rebind() method in
                    //PreRender event in order for the changes to take effect.
                    //GridDataItem dataItem = e.Item as GridDataItem;
                    //dataItem.Edit = true;
                }
 
                if (e.Item is GridFilteringItem)
                {
                }
            }
            catch (Exception ex)
            {
                LogError(ex);
                show_error_message(ex.Message);
            }
        }
 
 
  
        //Get the values from the different editors prior the synchronization of the database.
        private object GetColumnValue(GridColumn column, GridDataItem item)
        {
            Hashtable table = new Hashtable();
            item.ExtractValues(table);
            return table[column.UniqueName];
        }
 
        ////Provide the needed information to the editor control of the different columns
        //private void PrepareEditorControl(GridColumn column, int i, GridDataItem item)
        //{
        //    switch (column.ColumnType)
        //    {
        //        case "GridBoundColumn":
        //            {
        //                TextBox textBox = (item[column.UniqueName].Controls[0]) as TextBox;
        //                //SetupControl(textBox, item.ItemIndex, i);
        //                textBox.Width = Unit.Percentage(100);
        //                //textBox.Style.Add("width", "100%");
        //            }
        //            break;
        //        case "GridCheckBoxColumn":
        //            {
        //                CheckBox checkBox = (item[column.UniqueName].Controls[0]) as CheckBox;
        //                //SetupControl(checkBox, item.ItemIndex, i);
        //            }
        //            break;
        //        case "GridDropDownColumn":
        //            {
        //                GridDropDownColumn dropDownColumn = column as GridDropDownColumn;
        //                switch (dropDownColumn.DropDownControlType)
        //                {
        //                    case GridDropDownColumnControlType.DropDownList:
        //                        {
        //                            DropDownList dropDown = (item[column.UniqueName].Controls[0]) as DropDownList;
        //                            //SetupControl(dropDown, item.ItemIndex, i);
        //                        }
        //                        break;
        //                    default:
        //                        {
        //                            RadComboBox comboBox = (item[column.UniqueName].Controls[0]) as RadComboBox;
        //                            //SetupControl(comboBox, item.ItemIndex, i);
        //                        }
        //                        break;
        //                }
        //            }
        //            break;
        //        case "GridDateTimeColumn":
        //            {
        //                RadDatePicker picker = (item[column.UniqueName].Controls[0]) as RadDatePicker;
        //                //SetupControl(picker.DateInput, item.ItemIndex, i);
        //                //SetupControl(picker, item.ItemIndex, i);
 
 
        //                RadDateInput dateInput = item[column.UniqueName].Controls[0] as RadDateInput;
        //                if (dateInput != null)
        //                {
        //                    dateInput.Skin = "";
        //                    dateInput.EnableEmbeddedBaseStylesheet = false;
        //                    dateInput.EnableEmbeddedSkins = false;
        //                    //SetupControl(dateInput, item.ItemIndex, i);
        //                }
 
        //            }
        //            break;
        //        case "GridNumericColumn":
        //            {
        //                RadNumericTextBox numericTextBox = (item[column.UniqueName].Controls[0]) as RadNumericTextBox;
 
        //                if (numericTextBox != null)
        //                {
        //                    numericTextBox.SelectionOnFocus = SelectionOnFocus.None;
        //                    numericTextBox.IncrementSettings.InterceptArrowKeys = false;
        //                    numericTextBox.Width = Unit.Pixel(140);
        //                    numericTextBox.Skin = "";
        //                    //SetupControl(numericTextBox, item.ItemIndex, i);
        //                }
        //            }
        //            break;
        //        case "GridMaskedColumn":
        //            {
        //                RadMaskedTextBox maskedTextBox = (item[column.UniqueName].Controls[0]) as RadMaskedTextBox;
 
        //                if (maskedTextBox != null)
        //                {
        //                    maskedTextBox.SelectionOnFocus = SelectionOnFocus.None;
        //                    maskedTextBox.Skin = "";
        //                    maskedTextBox.Width = Unit.Pixel(140);
        //                    //SetupControl(maskedTextBox, item.ItemIndex, i);
        //                }
        //            }
        //            break;
        //    }
        //}
 
        //private void SetupControl(WebControl control, int itemIndex, int colIndex)
        //{
        //    if (control == null) return;
 
        //    CheckBox checkBox = control as CheckBox;
        //    RadDatePicker picker = control as RadDatePicker;
        //    if (checkBox != null)
        //    {
        //        //Adds the click and dblclick event handlers to the HTML element
        //        control.Attributes.Add("ondblclick", "cellDoubleClickFunction('" + control.ClientID + "');");
        //        control.Attributes.Add("onclick", "cellClick('" + control.ClientID + "');");
        //        checkBox.InputAttributes.Add("class", "row" + itemIndex + "col" + colIndex);
        //        return;
        //    }
        //    else if (picker != null)
        //    {
        //        picker.DateInput.Skin = "";
        //        picker.Skin = "";
        //        picker.DateInput.EnableEmbeddedBaseStylesheet = false;
        //        picker.DateInput.EnableEmbeddedSkins = false;
        //        //We enable the PopUpOnFocus so when we focus the cell with the keyboard to be
        //        //able to choose the directly without clicking the cell again.
        //        picker.ShowPopupOnFocus = true;
        //        //Enable the keyboard navigation.        
        //        picker.SharedCalendar.EnableKeyboardNavigation = true;
        //        //Hide the button for the PopUp, we do not need this, because we are showing the popup on focus.
        //        picker.DatePopupButton.Visible = false;
        //        //We hook this event in order to clear the selected cells and continue the navigation with the keyboard.
        //        picker.ClientEvents.OnPopupClosing = "PopUpClosing";
        //        //Adds the click and dblclick event handlers to the HTML element
        //        picker.Attributes.Add("ondblclick", "cellDoubleClickFunction('" + picker.ClientID + "');");
        //        picker.Attributes.Add("onclick", "cellClick('" + picker.ClientID + "');");
        //        //Assign a unique CSS class to each editor control so we could access it afterwards through JQuery.
        //        picker.DateInput.CssClass = "row" + itemIndex + "col" + colIndex;
        //        return;
        //    }
        //    //Adds the click and dblclick event handlers to the HTML element
        //    control.Attributes.Add("ondblclick", "cellDoubleClickFunction('" + control.ClientID + "');");
        //    control.Attributes.Add("onclick", "cellClick('" + control.ClientID + "');");
        //    //Assign a unique CSS class to each editor control so we could access it afterwards through JQuery.
        //    control.CssClass = "row" + itemIndex.ToString() + "col" + colIndex.ToString();
        //}
 
 
        protected void cboFunctionTool_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
        {
            using (FunctionDataContext sdc = new FunctionDataContext(string.Empty))
            {
                RadComboBox ddl = (RadComboBox)sender;
                foreach (Function_FunctionToolCBO this_item in sdc.GetFunction_FunctionToolList().ToList<Function_FunctionToolCBO>())
                {
                    ddl.Items.Add(new Telerik.Web.UI.RadComboBoxItem(this_item.FunctionToolName.ToString(), this_item.FunctionToolId.ToString()));
                }
 
            }
 
        }
 
        private void FillUsers(RadComboBox ddl)
        {
            using (GeneralDataContext sdc = new GeneralDataContext(string.Empty))
            {
                foreach (SystemUserCBO this_item in sdc.GetUserList().ToList<SystemUserCBO>())
                {
                    ddl.Items.Add(new Telerik.Web.UI.RadComboBoxItem(this_item.UserName.ToString(), this_item.UserId.ToString()));
                }
 
            }
 
        }
 
        private void PopulateDivisions(RadComboBox ddl)
        {
            using (CommonDataContext sdc = new CommonDataContext(string.Empty))
            {
                foreach (Division this_item in sdc.GetDivisionList().ToList<Division>())
                {
                    ddl.Items.Add(new Telerik.Web.UI.RadComboBoxItem(this_item.DivisionName.ToString(), this_item.dimDivisionId.ToString()));
                }
            }
        }
 
        private void PopulatePriority(RadComboBox ddl)
        {
            using (PrioritiesDataContext sdc = new PrioritiesDataContext(string.Empty))
            {
                foreach (PriorityCBO this_item in sdc.GetPrioritiesList().ToList<PriorityCBO>())
                {
                    ddl.Items.Add(new Telerik.Web.UI.RadComboBoxItem(this_item.PriorityName.ToString(), this_item.PriorityId.ToString()));
                }
            }
 
        }
 
        private void PopulateCategory(RadComboBox ddl)
        {
            using (CategoriesDataContext sdc = new CategoriesDataContext(string.Empty))
            {
                foreach (RequestTypeCBO this_item in sdc.GetRequestTypeList().ToList<RequestTypeCBO>())
                {
                    ddl.Items.Add(new Telerik.Web.UI.RadComboBoxItem(this_item.RequestTypeName.ToString(), this_item.RequestTypeId.ToString()));
                }
            }
 
        }
 
        private void PopulateStatus(RadComboBox ddl)
        {
            using (RequestsDataContext rdc = new RequestsDataContext(string.Empty))
            {
                foreach (RequestStatusCBO this_item in rdc.GetRequestStatusList().ToList<RequestStatusCBO>())
                {
                    ddl.Items.Add(new Telerik.Web.UI.RadComboBoxItem(this_item.RequestName.ToString(), this_item.RequestStatusId.ToString()));
                }
            }
        }
 
        private void PopulateSites(RadComboBox ddl)
        {
            using (SystemDataContext sdc = new SystemDataContext(string.Empty))
            {
                foreach (SystemSiteCBO this_item in sdc.GetSitesList().ToList<SystemSiteCBO>())
                {
                    ddl.Items.Add(new Telerik.Web.UI.RadComboBoxItem(this_item.SiteName.ToString(), this_item.SiteId.ToString()));
                }
            }
        }
         
        protected void cboAssignedTo_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
        {
            FillUsers((RadComboBox)sender);
        }
 
        protected void cboRequestedBy_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
        {
            FillUsers((RadComboBox)sender);
        }
 
        protected void cboRequestType_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
        {
            PopulateCategory((RadComboBox)sender);
        }
 
        protected void cboPriority_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
        {
            PopulatePriority((RadComboBox)sender);
        }
 
        protected void cboDivision_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
        {
            PopulateDivisions((RadComboBox)sender);
        }
 
        protected void cboStatus_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
        {
            PopulateStatus((RadComboBox)sender);
        }
 
        protected void cboSite_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
        {
            PopulateSites((RadComboBox)sender);
        }
 
 
        //protected void requests_grid_PreRender(object sender, EventArgs e)
        //{
        //    foreach (GridDataItem item in requests_grid.MasterTableView.Items)
        //    {
        //        if (item.IsInEditMode)
        //        {
        //            for (int i = 2; i < requests_grid.MasterTableView.RenderColumns.Length; i++)
        //            {
        //                //We this loop to provide the necessary information to the editor controls.
        //                //We will use this information to navigate through the cells of RadGrid.
        //                GridColumn column = requests_grid.MasterTableView.RenderColumns[i];
        //                PrepareEditorControl(column, i, item);
        //            }
        //        }
 
        //    }
 
        //}
 
 
 
 
 
     }
}

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 29 Aug 2014, 06:18 AM
Hi Scott,

Please take a look at the following sample code snippet to get the RadComboBox values in batch edit:

ASPX:
<telerik:RadGrid ID="requests_grid" runat="server" Skin="Metro" AutoGenerateColumns="false" AllowSorting="true" OnNeedDataSource="requests_grid_NeedDataSource" OnBatchEditCommand="requests_grid_BatchEditCommand">
    <MasterTableView DataKeyNames="OrderID" CommandItemDisplay="Top" EditMode="Batch">
        <BatchEditingSettings EditType="Row" OpenEditingEvent="Click" />
        <Columns>
            <telerik:GridBoundColumn DataField="OrderID" HeaderText="ID" ReadOnly="true">
                <ItemStyle HorizontalAlign="Center" />
            </telerik:GridBoundColumn>
            <telerik:GridTemplateColumn HeaderText="ShipCity" UniqueName="ShipCity" DataField="ShipCity">
                <ItemTemplate>
                    <%# Eval("ShipCity")%>
                </ItemTemplate>
                <EditItemTemplate>
                    <telerik:RadTextBox runat="server" ID="txtShipCity">
                    </telerik:RadTextBox>
                </EditItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn HeaderText="ShipCountry" UniqueName="ShipCountry" DataField="ShipCountry">
                <ItemTemplate>
                    <%# Eval("ShipCountry")%>
                </ItemTemplate>
                <EditItemTemplate>
                    <telerik:RadComboBox runat="server" ID="rcbShipCountry" EnableLoadOnDemand="true" Width="100%" MarkFirstMatch="true" OnItemsRequested="rcbShipCountry_ItemsRequested">
                    </telerik:RadComboBox>
                </EditItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

C#:
protected void requests_grid_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    requests_grid.DataSourceID = "SqlDataSource1";
}
 
private void SaveRequest(GridBatchEditingCommand grdItem)
{
    Hashtable newValues = grdItem.NewValues;
    Hashtable oldValues = grdItem.OldValues;
    string id = grdItem.Item.GetDataKeyValue("OrderID").ToString();
    //getting the Updated values
    string ShipCity = newValues["ShipCity"].ToString();
    string ShipCountry = newValues["ShipCountry"].ToString();
}
 
protected void requests_grid_BatchEditCommand(object sender, Telerik.Web.UI.GridBatchEditingEventArgs e)
{
    try
    {
        GridDataItem grdItem;
        foreach (GridBatchEditingCommand command in e.Commands)
        {
            grdItem = command.Item;
            if (command.Type == GridBatchEditingCommandType.Update)
            {
                SaveRequest(command);
            }
        }
    }
    catch (Exception ex)
    {
 
    }
}
protected void rcbShipCountry_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
{
    RadComboBox ddl = (RadComboBox)sender;
    ddl.DataSourceID = "SqlDataSource2";
    ddl.DataTextField = "ShipCountry";
    ddl.DataValueField = "ShipCountry";
    ddl.DataBind();
}

Thanks,
Shinu

Tags
Grid
Asked by
Scott
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Share this question
or