Hash table values Incorrect on in BatchEdit Mode

7 posts, 0 answers
  1. Ramey
    Ramey avatar
    19 posts
    Member since:
    Feb 2016

    Posted 18 Feb Link to this post

    I currently have a Grid with two rad comboboxes that are being displayed in the grid using tooltips and being handled by the batchManagerExtentions.js library.  The first combobox selection populates the second combobox and once that selection is made that is the value I need to be stored inside of the Database.  Once the selections have been made and the save all changes button has been clicked on the BatchEditCommand function where I am creating the newValues Hashtables the values are all thrown off, but they are being populated inside of the List<> correctly with the correct name / value / relation.  I've attached screenshots, JS code, markup and code behind.  Any help would be great!

    Markup:

    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
                <AjaxSettings>
                    <telerik:AjaxSetting AjaxControlID="RadGridUser">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="RadGridUser" />
                            <telerik:AjaxUpdatedControl ControlID="RadGridWorkArea" LoadingPanelID="RadAjaxLoadingPanel1" />
                            <telerik:AjaxUpdatedControl ControlID="RelatedComboBoxesToolTip" />
                        </UpdatedControls>
                    </telerik:AjaxSetting>
                    <telerik:AjaxSetting AjaxControlID="RadGridWorkArea">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="RelatedComboBoxesToolTip" />
                        </UpdatedControls>
                    </telerik:AjaxSetting>
                </AjaxSettings>
            </telerik:RadAjaxManager>
     
    <telerik:RadToolTip runat="server" ID="RelatedComboBoxesToolTip" OffsetY="0" RenderInPageRoot="false" 
    HideEvent="FromCode" AutoCloseDelay="0" RelativeTo="Element" CssClass="RelatedCombosToolTip"
    ShowEvent="FromCode" Position="Center" Skin="Default">
    <telerik:RadComboBox runat="server" Width="100%" EnableLoadOnDemand="true" OnItemsRequested="RadComboBox1_ItemsRequested">
    </telerik:RadComboBox>
    <telerik:RadToolTip runat="server" Skin="Metro" OffsetY="0" EnableShadow="false" ShowEvent="FromCode" Position="TopCenter"></telerik:RadToolTip>
    </telerik:RadToolTip>
     
                <telerik:RadGrid ID="RadGridWorkArea" runat="server" DataSourceID="WorkAreaDataSource" Width="1000px" OnItemCommand="RadGridWorkArea_ItemCommand"
    AutoGenerateDeleteColumn="true" OnItemDataBound="RadGridWorkArea_ItemDataBound" ShowFooter="true" AllowAutomaticUpdates="false" OnBatchEditCommand="RadGridWorkArea_BatchEditCommand">
    <MasterTableView EditMode="Batch" CommandItemDisplay="Top" AutoGenerateColumns="false" DataKeyNames="bpSystemUserAssignID">
    <ItemStyle Height="40px" />
    <AlternatingItemStyle Height="40px" />
    <Columns>
                            <telerik:GridBoundColumn DataField="bpSystemUserAssignID" UniqueName="bpSystemUserAssignID" ReadOnly="true" HeaderText="ID" Visible="false"></telerik:GridBoundColumn>
                            <telerik:GridTemplateColumn DataField="bpSystemID" UniqueName="bpSystemID" HeaderText="System" HeaderStyle-Width="250px">
                                <ItemTemplate>
                                    <%# Eval("bpSystemName") %>
                                </ItemTemplate>
                                <EditItemTemplate></EditItemTemplate>
                            </telerik:GridTemplateColumn>
    <telerik:GridTemplateColumn DataField="bpSubSystemID" UniqueName="bpSubSystemID" HeaderText="Sub-System" HeaderStyle-Width="250px">
    <ItemTemplate>
    <%# Eval("bpSubSystemName")%>
    </ItemTemplate>
    <EditItemTemplate></EditItemTemplate>
    </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn UniqueName="Template1" HeaderStyle-Width="60px" HeaderText="Work Area Percentage">
                                <ItemTemplate>
                                    <asp:Label ID="percentLbl" runat="server" Text='<%# Eval("bpWorkPercentage") %>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <telerik:RadNumericTextBox ID="TextBox1" runat="server" DbValue='<%# Eval("bpWorkPercentage") %>' Type="Percent" NumberFormat-DecimalDigits="0">
                                        <ClientEvents OnBlur="Blur" OnFocus="Focus" />
                                    </telerik:RadNumericTextBox>
                                </EditItemTemplate>
                                <FooterTemplate>
                                    <telerik:RadNumericTextBox ID="TextBox2" runat="server" Type="Percent" NumberFormat-DecimalDigits="0">
                                        <ClientEvents OnLoad="Load" />
                                    </telerik:RadNumericTextBox>
                                </FooterTemplate>
                            </telerik:GridTemplateColumn>                        
                        </Columns>
    </MasterTableView>
    <ClientSettings>
    <ClientEvents OnUserAction="userAction" OnGridCreated="gridCreated" />
    </ClientSettings>
    </telerik:RadGrid>
    Code-Behind

    protected void RadGridWorkArea_BatchEditCommand(object sender, GridBatchEditingEventArgs e)
            {
                List<DemoItem> subsystemIDs = (List<DemoItem>)Session["subsystems"];
                foreach (GridBatchEditingCommand command in e.Commands)
                {
                    if (command.Type == GridBatchEditingCommandType.Update)
                    {
                        Hashtable newValues = command.NewValues;
                        Hashtable oldValues = command.OldValues;
                        string id = newValues["bpSubSystemID"].ToString();
                    }
                }
            }

     

    JS

       var grid1Validator;
     
       function gridCreated(sender, args) {
           // == Batch Editing - Related ComboBoxes Manager == 
           var relatedComboBoxesManager = new BatchExtensions.RelatedComboBoxesManager().init({
               grid: sender,
               toolTipID: "<%=RelatedComboBoxesToolTip.ClientID%>",
               relations: [
    {
       columnName: "bpSystemID"
    },
    {
       columnName: "bpSubSystemID",
       relatedTo: "bpSystemID"
    }
    ]
           });
     
           // == Batch Editing - Validation Manager == 
           grid1Validator = new BatchExtensions.ValidationManager().init({
               grid: sender,
               validators: [
                                {
                                    columnName: "bpSystemID",
                                    errorMessage: "- Required -"
                                },
                                {
                                    columnName: "bpSubSystemID",
                                    errorMessage: "- Required -"
                                },
                                {
                                    columnName: "Template1",
                                    errorMessage: "",
                                    toolTipMessage: "Select a positive number",
                                    validationFunction: function (value) {
                                        return value >= 0;
                                    }
                                },
    ]
           });
       }
     
       function userAction(sender, args) {
           //You can use this event to alert the user that there are changes in the grid and 
           //cancel operations like paging, filtering, etc.
           //debugger;
           if (!grid1Validator.isValid()) {
               args.set_cancel(true);
           }
       }
     
       function PopUpShowing(sender, eventArgs) {
           popUp = eventArgs.get_popUp();
           var gridWidth = sender.get_element().offsetWidth;
           var gridHeight = sender.get_element().offsetHeight;
           var popUpWidth = popUp.style.width.substr(0, popUp.style.width.indexOf("px"));
           var popUpHeight = popUp.style.height.substr(0, popUp.style.height.indexOf("px"));
           popUp.style.left = ((gridWidth - popUpWidth) / 2 + sender.get_element().offsetLeft).toString() + "px";
           popUp.style.top = ((gridHeight - popUpHeight) / 2 + sender.get_element().offsetTop).toString() + "px";
       }
     
       function RowDblClick(sender, eventArgs) {
           sender.get_masterTableView().editItem(eventArgs.get_itemIndexHierarchical());
       }

    Thanks,

    Ramey

  2. Ramey
    Ramey avatar
    19 posts
    Member since:
    Feb 2016

    Posted 22 Feb in reply to Ramey Link to this post

    Has anyone been able to look at my code or has used this code library? 
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 23 Feb Link to this post

    Hello Ramey,

    You can use the UpdateCommand and InsertCommand events to save the changes that were made by the user. I tested the behavior and the records seem to be updated as expected on my end.

    Please give the attached sample a try and let me know how it works for you. If I am missing something, let me know.

    On a side note, please avoid submitting duplicate threads. This would enable anyone with similar issue to find a solution faster. I suggest we continue the conversation in this thread.

    Regards,
    Viktor Tachev
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  5. Ramey
    Ramey avatar
    19 posts
    Member since:
    Feb 2016

    Posted 23 Feb in reply to Viktor Tachev Link to this post

    Viktor,
    Thank you for your response.  I copied your update command and modified it slightly to meet my needs but it is still returning a -1 for my bpSubSystemID value.  When I am placing the values into the list that is populating the radcombobox the values are correct.  You can see in the attached screen shot that the value is still -1 when it should actually be 6.  The bpWorkPercentage is correct, and so is the bpSystemUserAssignID but those are bound columns.  The bpWorkPercentage will change in the future but for now I need to get the correct bpSubSystemID.  If you need additional code or screen shots please let me know.  Sorry for the multiple threads.  I have a deadline to meet and this is really putting me at a standstill.  
    Thanks,
    Ramey
  6. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 26 Feb Link to this post

    Hello Ramey,

    Would you modify the sample from my previous post in a way that the behavior is observed and send it back? This way we will be able to debug the code and look for what is causing the issue.

    Regards,
    Viktor Tachev
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  7. Ramey
    Ramey avatar
    19 posts
    Member since:
    Feb 2016

    Posted 26 Feb in reply to Viktor Tachev Link to this post

    Viktor,
    I  modified the .aspx page and the .aspx.cs page to some of the code in my application.  For now I have only included the update part.  Also when I do click the insert button I get a Javascript error saying it is not able to find the class name....I opened up another post about that earlier...and you responded to it as well...but since these issues are both dealing with the same project I thought that it would be alright to mention it here.  I also wanted to ask if you would mind helping me with some custom java script so that I can calculate the field bpWorkPercentage in the footer on the fly.  I need it to be once I user enters in a new work area number that it will automatically calculate in real time in the footer, but it doesn't just need to calculate edited records but all records that are in the grid, i.e. if record one was modified to 50 but records two and 3 stayed the same it would still total up to 100.
    Thanks,
    Ramey

    Markup:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default_Demo.aspx.cs" Inherits="Default_Demo"%>
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="act1" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <!DOCTYPE html>
     
    <head id="Head1" runat="server">
        <title></title>
        <style type="text/css">
             
        </style>
        <link href="batchManagerExtensions.css" rel="stylesheet" />
    </head>
    <body>
        <form id="form1" runat="server">
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
                <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" />
                    <asp:ScriptReference Path="~/Temp/20160223/batchManagerExtentions.js" />
                </Scripts>
            </telerik:RadScriptManager>
     
            <telerik:RadFormDecorator runat="server" DecoratedControls="All" />
            <telerik:RadSkinManager runat="server" ShowChooser="true" Skin="Silk"></telerik:RadSkinManager>
            <br />
            <br />
     
            <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
                <script type="text/javascript">
                    var grid1Validator;
     
                    function gridCreated(sender, args) {
                        // == Batch Editing - Related ComboBoxes Manager ==
                        var relatedComboBoxesManager = new BatchExtensions.RelatedComboBoxesManager().init({
                            grid: sender,
                            toolTipID: "<%=RelatedComboBoxesToolTip.ClientID%>",
                            relations: [
                                {
                                    columnName: "bpSystemID"
                                },
                                {
                                    columnName: "bpSubSystemID",
                                    relatedTo: "bpSystemID"
                                }
                            ]
                        });
     
                        // == Batch Editing - Validation Manager ==
                        grid1Validator = new BatchExtensions.ValidationManager().init({
                            grid: sender,
                            validators: [
                                {
                                    columnName: "bpSystemID",
                                    errorMessage: "- Required -"
                                },
                                {
                                    columnName: "bpSubSystemID",
                                    errorMessage: "- Required -"
                                },
                                {
                                    columnName: "bpWorkPercentage",
                                    errorMessage: "",
                                    toolTipMessage: "Select a positive number",
                                    validationFunction: function (value) {
                                        return value >= 0;
                                    }
                                },
                            ]
                        });
                    }
     
                    function userAction(sender, args) {
                        //You can use this event to alert the user that there are changes in the grid and
                        //cancel operations like paging, filtering, etc.
                        //debugger;
                        if (!grid1Validator.isValid()) {
                            args.set_cancel(true);
                        }
                    }
     
                </script>
            </telerik:RadCodeBlock>
            <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
                <AjaxSettings>
                    <telerik:AjaxSetting AjaxControlID="RadGridUser">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="RadGridUser" />
                            <telerik:AjaxUpdatedControl ControlID="RadGridWorkArea" LoadingPanelID="RadAjaxLoadingPanel1" />
                            <telerik:AjaxUpdatedControl ControlID="RelatedComboBoxesToolTip" />
                        </UpdatedControls>
                    </telerik:AjaxSetting>
                    <telerik:AjaxSetting AjaxControlID="RadGridWorkArea">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="RelatedComboBoxesToolTip" />
                        </UpdatedControls>
                    </telerik:AjaxSetting>
                </AjaxSettings>
            </telerik:RadAjaxManager>
            <asp:HiddenField ID="hiddenUserID" runat="server" />
            <telerik:RadGrid RenderMode="Lightweight" ID="RadGridUser" runat="server" AllowPaging="true" ShowFooter="true"
                AllowSorting="true" AutoGenerateColumns="false" ShowStatusBar="false" EnableViewState="false"
                OnPreRender="RadGridUser_PreRender" OnUpdateCommand="RadGridUser_UpdateCommand"
                OnInsertCommand="RadGridUser_InsertCommand" OnDeleteCommand="RadGridUser_DeleteCommand" OnItemCommand="RadGridUser_ItemCommand" DataSourceID="GetAllUsers">
                <MasterTableView Width="100%" EditMode="PopUp" CommandItemDisplay="Top" DataKeyNames="bpUserID">
                    <EditFormSettings CaptionFormatString="Edit Employee: {0}" CaptionDataField="bpUserName">
                        <PopUpSettings Modal="true" />
                    </EditFormSettings>
                    <Columns>                       
                        <telerik:GridBoundColumn DataField="bpUserID" DataType="System.Int32" HeaderText="User ID"
                            ReadOnly="true" SortExpression="bpUserID" UniqueName="bpUserID" Visible="false">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn UniqueName="bpUserName" HeaderText="User Name" DataField="bpUserName">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn UniqueName="bpOrgName" HeaderText="Organization Name" DataField="bpOrgName">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn UniqueName="bpUserRoleName" HeaderText="Role" DataField="bpUserRoleName">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn UniqueName="bpUserTitleName" HeaderText="Title" DataField="bpUserTitleName">
                        </telerik:GridBoundColumn>
                    </Columns>
                    <EditFormSettings UserControlName="../UserControls/UserDetails.ascx" EditFormType="WebUserControl">
                        <EditColumn UniqueName="EditCommandColumn1"></EditColumn>
                    </EditFormSettings>
                </MasterTableView>
                <ClientSettings AllowKeyboardNavigation="true" EnablePostBackOnRowClick="true">
                    <ClientEvents OnRowDblClick="RowDblClick" OnPopUpShowing="PopUpShowing" />
                    <Selecting AllowRowSelect="true" />
                </ClientSettings>   
            </telerik:RadGrid>
                <telerik:RadToolTip runat="server" ID="RelatedComboBoxesToolTip" OffsetY="0" RenderInPageRoot="false"
                    HideEvent="FromCode" AutoCloseDelay="0" RelativeTo="Element" CssClass="RelatedCombosToolTip"
                    ShowEvent="FromCode" Position="Center" Skin="Default">
                    <telerik:RadComboBox runat="server" Width="100%" EnableLoadOnDemand="true" OnItemsRequested="RadComboBox1_ItemsRequested">
                    </telerik:RadComboBox>
                    <telerik:RadToolTip runat="server" Skin="Metro" OffsetY="0" EnableShadow="false" ShowEvent="FromCode" Position="TopCenter"></telerik:RadToolTip>
                </telerik:RadToolTip>
     
                <telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource" DataSourceID="WorkAreaDataSource" Width="1000px"
                    OnBatchEditCommand="RadGrid1_BatchEditCommand"
                    OnUpdateCommand="RadGrid1_UpdateCommand" OnInsertCommand="RadGrid1_InsertCommand">
                    <MasterTableView EditMode="Batch" CommandItemDisplay="Top" AutoGenerateColumns="false">
                        <ItemStyle Height="40px" />
                        <AlternatingItemStyle Height="40px" />
                        <Columns>
                            <telerik:GridBoundColumn DataField="bpSystemUserAssignID" UniqueName="bpSystemUserAssignID" ReadOnly="true" HeaderText="ID" Visible="false"></telerik:GridBoundColumn>
                            <telerik:GridTemplateColumn DataField="bpSystemID" UniqueName="bpSystemID" HeaderText="System" HeaderStyle-Width="250px">
                                <ItemTemplate>
                                    <%# Eval("bpSystemName") %>
                                </ItemTemplate>
                                <EditItemTemplate></EditItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn DataField="bpSubSystemName" UniqueName="bpSubSystemID" HeaderText="Sub-System" HeaderStyle-Width="250px">
                                <ItemTemplate>
                                    <%# Eval("bpSubSystemName")%>
                                </ItemTemplate>
                                <EditItemTemplate></EditItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridBoundColumn DataField="bpWorkPercentage" Aggregate="None" UniqueName="bpWorkPercentage1" DataType="System.Int32" ></telerik:GridBoundColumn>
                        </Columns>
                    </MasterTableView>
                    <ClientSettings>
                        <ClientEvents OnUserAction="userAction" OnGridCreated="gridCreated" />
                    </ClientSettings>
                </telerik:RadGrid>
                <asp:ObjectDataSource ID="WorkAreaDataSource" runat="server" SelectMethod="GetSystemInfoByUser" UpdateMethod="BPprocUpdateWorkAreaByUser" TypeName="ProductionTracking.Core.BlueprintBLL"
                    OldValuesParameterFormatString="{0}">
                <SelectParameters>
                    <asp:ControlParameter ControlID="RadGridUser" Name="bpUserID" DefaultValue="" PropertyName="SelectedValues['bpUserID']" Type="Int32" />
                </SelectParameters>
                <DeleteParameters>
                    <asp:ControlParameter ControlID="RadGridUser" Name="bpUserID" DefaultValue="" PropertyName="SelectedValues['bpUserID']" Type="Int32" />
                </DeleteParameters>
                <InsertParameters>
                    <asp:ControlParameter ControlID="RadGridUser" Name="bpUserID" DefaultValue="" PropertyName="SelectedValues['bpUserID']" Type="Int32" />
                    <asp:Parameter Name="bpSubSystemID" Type="Int32" />
                    <asp:Parameter Name="bpWorkPercentage" Type="String" />
                </InsertParameters>
                <UpdateParameters>
                    <asp:Parameter  Name="bpSubSystemID" Type="Int32" />
                    <asp:Parameter Name="bpWorkPercentage" Type="String" />
                    <asp:Parameter DefaultValue="0" Name="bpSystemID" Type="Int32" />
                    <asp:Parameter Name="bpSystemUserAssignID" Type="Int32" />
                </UpdateParameters>
            </asp:ObjectDataSource>
        </form>
    </body>
    </html>

    C#:

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Data;
    using System.Data.Common;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.Text;
    using System.Web.Services;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Web.UI;
    using System.Linq;
    using System.IO;
     
    namespace WebApplication1
    {
     
        public partial class Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                //System.Threading.Thread.Sleep(100);
            }
     
            //protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
            //{
            //    (sender as RadGrid).DataSource = GridData;
            //}
     
     
            //public DataTable GridData
            //{
            //    get
            //    {
            //        DataTable data;
     
            //        if (Session["GridData"] == null)
            //        {
            //            data = GenerateData();
     
            //            Session["GridData"] = data;
            //        }
     
            //        data = (DataTable)Session["GridData"];
     
            //        return data;
            //    }
     
            //    set
            //    {
            //        Session["GridData"] = value;
            //    }
            //}
     
            //public DataTable GenerateData()
            //{
            //    DataTable table = new DataTable();
            //    table.Columns.Add("ID", typeof(int));
            //    table.Columns.Add("Continent", typeof(string));
            //    table.Columns.Add("Country", typeof(string));
            //    table.Columns.Add("City", typeof(string));
            //    table.Columns.Add("Numeric", typeof(int));
            //    table.Columns.Add("Date", typeof(DateTime));
     
            //    table.Rows.Add(1, "North America", "United States", "Washington", 5, DateTime.Now);
            //    table.Rows.Add(2, "North America", "United States", "New York", 2, DateTime.Now);
            //    table.Rows.Add(3, "Europe", "England", "London", 10, DateTime.Now);
            //    table.Rows.Add(4, "Europe", "France", "Paris", 23, DateTime.Now);
            //    table.Rows.Add(5, "North America", "Mexico", "Guadalajara", 32, DateTime.Now);
            //    table.Rows.Add(6, "Europe", "France", "Caen", 4, DateTime.Now);
     
            //    return table;
            //}
     
            protected void RadGridWorkArea_UpdateCommand(object sender, GridCommandEventArgs e)
            {
                //I only included the RadGridUser table just so you could see but it is using an object data source as well that retrives all users and once
                //a user is selected I user the ItemCommand function to store the value in a hidden field.
                hiddenUserID.Value = RadGridUser.SelectedValue.ToString();
                String ConnString = ConfigurationManager.ConnectionStrings["ProductionTracking"].ToString();
                SqlConnection MySqlConnection = new SqlConnection(ConnString);
                SqlDataAdapter MySqlDataAdapter = new SqlDataAdapter();
                MySqlDataAdapter.SelectCommand = new SqlCommand("BPprocGetSystemInfoByUser", MySqlConnection);
                MySqlDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure;
                MySqlDataAdapter.SelectCommand.Parameters.AddWithValue("@bpUserID", int.Parse(hiddenUserID.Value));
     
                DataTable newData = new DataTable();
                MySqlConnection.Open();
                try
                {
                    MySqlDataAdapter.Fill(newData);
                }
                finally
                {
                    MySqlConnection.Close();
                }
     
     
                Hashtable newValues = (e.CommandArgument as GridBatchEditingEventArgument).NewValues;
     
                DataRow[] row = newData.Select("bpSystemUserAssignID = " + newValues["bpSystemUserAssignID"]);
     
     
                row[0]["bpSystemUserAssignID"] = newValues["bpSystemUserAssignID"];
                row[0]["bpSubSystemID"] = newValues["bpSubSystemID"];
                row[0]["bpWorkPercentage"] = newValues["bpWorkPercentage"];
     
                newData.AcceptChanges();
            }
     
            protected void RadGrid1_InsertCommand(object sender, GridCommandEventArgs e)
            {
                Hashtable newValues = (e.CommandArgument as GridBatchEditingEventArgument).NewValues;
     
                DataTable newData = GridData;
     
                DataRow row = newData.NewRow();
     
                row["ID"] = newValues["ID"];
                row["Continent"] = newValues["Continent"];
                row["Country"] = newValues["Country"];
                row["City"] = newValues["City"];
                row["Numeric"] = newValues["Numeric"];
                row["Date"] = newValues["Date"];
     
                newData.Rows.Add(row);
            }
     
     
            protected void RadComboBox1_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
            {
                RadComboBox comboBox = sender as RadComboBox;
                string columnName = e.Context["ColumnName"].ToString();
                string relatedValue = e.Context["RelatedValue"] != null ? e.Context["RelatedValue"].ToString() : "";
     
     
                //Retrieve the RadComboBox data, based on the relatedValue and the columnName
                //--------------------------------------------------------
                List<DemoItem> items = new List<DemoItem>();
                if (columnName == "bpSystemID")
                {
                    items = DemoRelatedValues.GetSystem();
                }
                else if (columnName == "bpSubSystemID")
                {
                    items = DemoRelatedValues.GetSubSystems(relatedValue);
                    Session["subsystems"] = items;
     
     
                }
     
                if (items.Count > 0)
                {
                    foreach (DemoItem item in items)
                    {
                        comboBox.Items.Add(new RadComboBoxItem(item.Text));
                    }
                }
            }
     
            protected void RadGrid1_BatchEditCommand(object sender, GridBatchEditingEventArgs e)
            {
     
            }
     
            protected void Page_PreRender(object sender, EventArgs e)
            {
                GridTableView masterTable = RadGridWorkArea.MasterTableView;
                foreach (GridColumn column in masterTable.RenderColumns)
                {
                    if ((column is IGridEditableColumn) && (column as IGridEditableColumn).IsEditable && masterTable.GetBatchColumnEditor(column.UniqueName) != null)
                    {
                        Control container = (masterTable.GetBatchColumnEditor(column.UniqueName) as IGridColumnEditor).ContainerControl;
     
                        if (container != null && container.Controls.Count > 0)
                        {//Had to stick this part in a try catch for error purposes...I want to use something besides a GridBoundColumn for the Workarea percent so I can have on
                            //the fly totals in the grid footer but I never could get that to work
                            try
                            {
                                (container.Controls[0] as WebControl).Width = Unit.Percentage(100);
                            }
                            catch
                            {
     
                            }
                        }
                    }
     
                }
            }
        }
    }
     
     
    #region dummy-data
     
    public static class DemoRelatedValues
    {
        public static List<DemoItem> GetSystem()
        {
            ProductionTracking.Core.BlueprintBLL BluePrintBLL1 = new BlueprintBLL();       
            DataTable system = new DataTable();
            system = BluePrintBLL1.BPprocGetSystem();
            List<DemoItem> Systems = new List<DemoItem>();
     
            foreach (DataRow row in system.Rows)
            {
                Systems.Add(new DemoItem(int.Parse(row["bpSystemID"].ToString()), row["bpSystemName"].ToString()));
            }
     
            return Systems;
        }
     
        public static List<DemoItem> GetSubSystems(string bpSystemName)
        {
            ProductionTracking.Core.BlueprintBLL BluePrintBLL1 = new BlueprintBLL();
            DataTable subSystem = new DataTable();
            subSystem = BluePrintBLL1.BPGetSubSystemBySystemName(bpSystemName);
            List<DemoItem> SubSystems = new List<DemoItem>();
     
            foreach (DataRow row in subSystem.Rows)
            {
                SubSystems.Add(new DemoItem(int.Parse(row["bpSubSystemID"].ToString()), row["bpSubSystemName"].ToString(), int.Parse(row["bpSystemID"].ToString())));
            }
     
            return SubSystems;
        }
     
    }
     
     
    public class DemoItem
    {
        public int Value { get; set; }
        public string Text { get; set; }
        public int Relation { get; set; }
     
        public DemoItem(int value, string text, int relation)
        {
            this.Value = value;
            this.Text = text;
            this.Relation = relation;
        }
     
        public DemoItem(int value, string text)
        {
            this.Value = value;
            this.Text = text;
        }
    }
     
    #endregion

  8. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 02 Mar Link to this post

    Hi Ramey,

    I examined the code and noticed that you are using both NeedDataSource and DataSourceID to bind the grid. Note that this is not a supported scenario and can produce unexpected behavior. You should use only one approach to bind the RadGrid control - either NeedDataSource or declarative DataSource.

    Also, in the markup there is a template column with UniqueName set to bpSubSystemID. However, the actual data field used in it is bpSubSystemName. Make sure that you update the correct field in the code-behind. In case you will be using declarative DataSource ensure that the DataField is passed as parameter.

    Moreover, I noticed that AjaxControlToolkit is referenced on the page. Have in mind that the AjaxControlToolkit can break the functionality of our controls. Please ensure that you are not referencing the toolkit in the project. Also use the default ASP ScriptManager or the RadScriptManager.

    Regarding your other query. Since there is another thread for it I suggest we discuss the behavior there. This way the information in the threads will be consistent and easier to find.

    Regards,
    Viktor Tachev
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017