Rad Grid Insert Command Not Firing

22 posts, 0 answers
  1. Josh Sudbury
    Josh Sudbury avatar
    10 posts
    Member since:
    Apr 2010

    Posted 19 Apr 2010 Link to this post

    I am using Rad Grid with a UserControl for the edit and insert form.

    I have followed the code examples on the site and read the threads on the forum with people having a similar issue but I'm still having problems.

    The ability to edit the items works properly. And when I click on the "Add new record" button the user control shows up properly, awaiting information and clicking of the insert button, but when I click on insert the command specified in the control properties for inserts never fires. I've used break points in page load and on the first instruction in the NewsList_InsertCommand function to ensure that a postback is occuring, and it is, but the NewsList_InsertCommand function never fires.

    My Rad Grid Control:
    <telerik:RadGrid ID="NewsList" AutoGenerateColumns="false" 
                                            runat="server" AllowFilteringByColumn="True" 
                                            AllowPaging="True" AllowSorting="True" 
                                            GridLines="None" Skin="Office2007" 
                                            OnNeedDataSource="NewsList_NeedDataSource"   
                                            OnUpdateCommand="NewsList_UpdateCommand"   
                                            PageSize="20" 
                                            OnItemDataBound="NewsList_ItemDataBound" 
                                             OnInsertCommand="NewsList_InsertCommand">  
                                                <PagerStyle Mode="NextPrevAndNumeric" /> 
                                                <GroupingSettings CaseSensitive="False" /> 
                                                <ClientSettings> 
                                                    <Selecting AllowRowSelect="True" /> 
                                                </ClientSettings> 
                                                <MasterTableView TableLayout="Auto" EditMode="EditForms" CommandItemDisplay="Top" InsertItemDisplay="Top" InsertItemPageIndexAction="ShowItemOnCurrentPage">  
                                                    <EditFormSettings EditFormType="WebUserControl" UserControlName="~/UserControls/News/NewsManagementEditControl.ascx">  
                                                    </EditFormSettings> 
                                                    <Columns> 
                                                        <telerik:GridBoundColumn AutoPostBackOnFilter="True" DataField="NewsId"   
                                                            DataType="System.Int32" DefaultInsertValue="" HeaderText="News ID"   
                                                            ShowFilterIcon="False" SortExpression="NewsId" UniqueName="NewsId" Visible="false">  
                                                        </telerik:GridBoundColumn> 
                                                        <telerik:GridBoundColumn HeaderText="Title" DataField="Title"   
                                                            UniqueName="Title" SortExpression="Title"   
                                                            HeaderStyle-Width="450px" FilterControlWidth="450px" 
                                                            AutoPostBackOnFilter="true" CurrentFilterFunction="Contains"   
                                                            ShowFilterIcon="false">  
                                                            <HeaderStyle Width="450px" /> 
                                                        </telerik:GridBoundColumn> 
                                                        <telerik:GridBoundColumn HeaderText="Date Created" DataField="DateCreated" 
                                                            UniqueName="DateCreated" SortExpression="DateCreated" HeaderStyle-Width="50px" 
                                                            FilterControlWidth="50px" AutoPostBackOnFilter="true"   
                                                            CurrentFilterFunction="Contains" ShowFilterIcon="false">  
                                                            <HeaderStyle Width="50px" /> 
                                                        </telerik:GridBoundColumn> 
                                                        <telerik:GridBoundColumn HeaderText="Associated Apps" DataField="AssociatedApps" 
                                                            UniqueName="AssociatedApps" HeaderStyle-Width="180px" ShowFilterIcon="false">  
                                                            <HeaderStyle Width="180px" /> 
                                                        </telerik:GridBoundColumn> 
                                                        <telerik:GridEditCommandColumn UpdateText="Update" CancelText="Cancel" UniqueName="Edit" ButtonType="LinkButton">  
                                                        </telerik:GridEditCommandColumn> 
                                                        <telerik:GridButtonColumn CommandName="DeleteNews" 
                                                            Text="Delete" UniqueName="column2">  
                                                        </telerik:GridButtonColumn> 
                                                    </Columns> 
                                                </MasterTableView> 
                                        </telerik:RadGrid>    


    My Insert Function in the code behind file:
    protected void NewsList_InsertCommand(object sender, GridCommandEventArgs e)  
            {  
                UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);  
     
                var newTitleControl = (RadTextBox)userControl.FindControl("txtTitle");  
                var newDescriptionControl = (RadTextBox)userControl.FindControl("txtDescription");  
                var newContentControl = (RadEditor)userControl.FindControl("txtNewsContent");  
     
                if(String.IsNullOrEmpty(newTitleControl.Text) && String.IsNullOrEmpty(newDescriptionControl.Text) && String.IsNullOrEmpty(newContentControl.Text))  
                {  
                    return;  
                }  
     
                ONews newNewsItem = Engine.News(Globals.User.UserId).CreateNews(newTitleControl.Text, newDescriptionControl.Text,  
                                                            newContentControl.Text, Globals.User.UserId);  
     
                var applicationListRepeater = (Repeater) userControl.FindControl("rptApplicationList");  
                foreach (RepeaterItem app in applicationListRepeater.Items)  
                {  
                    var checkbox = (CheckBox) app.FindControl("application");  
                    var applicationId = int.Parse(checkbox.Attributes["applicationId"]);  
                    if (checkbox.Checked)  
                    {  
                        Engine.News(Globals.User.UserId).CreateApplicationNews(newNewsItem.NewsId, applicationId);  
                    }  
                } 


    My user control aspx file:
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="NewsManagementEditControl.ascx.cs" Inherits="InternalAdmin.UserControls.News.NewsManagementEditControl" %> 
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
     
    <asp:UpdatePanel ID="EditNewsSection" runat="server">  
        <ContentTemplate> 
            <table width="100%">  
                <tr> 
                    <td valign="top">  
                        <div class="Block">  
                            <div class="Block-tl">  
                            </div> 
                            <div class="Block-tr">  
                            </div> 
                            <div class="Block-bl">  
                            </div> 
                            <div class="Block-br">  
                            </div> 
                            <div class="Block-tc">  
                            </div> 
                            <div class="Block-bc">  
                            </div> 
                            <div class="Block-cl">  
                            </div> 
                            <div class="Block-cr">  
                            </div> 
                            <div class="Block-cc">  
                            </div> 
                            <div class="Block-body">  
                                <div class="BlockHeader">  
                                    <div class="t">  
                                        News Item Details</div> 
                                </div> 
                                <div class="BlockContent">  
                                    <div class="BlockContent-body">  
                                        <table> 
                                            <tr> 
                                                <tr> 
                                                    <td> 
                                                        <asp:Label ID="lblNewsId" runat="server" Text=""></asp:Label>    
                                                    </td> 
                                                </tr> 
                                                <td> 
                                                    <strong>Title</strong> 
                                                </td> 
                                                <td rowspan="6" valign="top">  
                                                    <table> 
                                                        <tr> 
                                                            <td> 
                                                                <strong> 
                                                                    Associated Applications  
                                                                </strong> 
                                                            </td> 
                                                        </tr> 
                                                        <asp:Repeater ID="rptApplicationList" runat="server" OnItemDataBound="rptApplicationList_ItemDataBound">  
                                                            <ItemTemplate> 
                                                                <tr> 
                                                                    <td> 
                                                                        <asp:CheckBox ID="application" Text="" runat="server"/>  
                                                                    </td> 
                                                                </tr> 
                                                            </ItemTemplate> 
                                                        </asp:Repeater> 
                                                    </table> 
                                                </td> 
                                            </tr> 
                                            <tr> 
                                                <td> 
                                                    <telerik:RadTextBox ID="txtTitle" MaxLength="200" runat="server">  
                                                    </telerik:RadTextBox> 
                                                    <br /> 
                                                    <br /> 
                                                </td> 
                                            </tr> 
                                            <tr> 
                                                <td> 
                                                    <strong>Description</strong> 
                                                </td> 
                                            </tr> 
                                            <tr> 
                                                <td> 
                                                    <telerik:RadTextBox ID="txtDescription" MaxLength="500" runat="server">  
                                                    </telerik:RadTextBox> 
                                                    <br /> 
                                                    <br /> 
                                                </td> 
                                            </tr> 
                                            <tr> 
                                                <td> 
                                                    <strong>News Content</strong> 
                                                </td> 
                                            </tr> 
                                            <tr> 
                                                <td> 
                                                    <telerik:RadEditor ID="txtNewsContent" runat="server" Height="300px"   
                                                        Width="500px" EditModes="Design"   
                                                        ToolbarMode="Default" StripFormattingOnPaste="AllExceptNewLines">  
                                                        <CssFiles> 
                                                            <telerik:EditorCssFile Value="~/CSS/Editor.css" /> 
                                                        </CssFiles> 
                                                        <tools> 
                                                            <telerik:EditorToolGroup> 
                                                                <telerik:EditorTool Name="Bold" /> 
                                                                <telerik:EditorTool Name="Underline" /> 
                                                                <telerik:EditorSeparator /> 
                                                                <telerik:EditorTool Name="Cut" /> 
                                                                <telerik:EditorTool Name="Copy"/>  
                                                                <telerik:EditorTool Name="Paste"/>  
                                                                <telerik:EditorSeparator /> 
                                                                <telerik:EditorTool Name="Undo" /> 
                                                                <telerik:EditorTool Name="Redo"/>  
                                                            </telerik:EditorToolGroup> 
                                                        </tools> 
                                                    </telerik:RadEditor> 
                                                </td> 
                                            </tr> 
                                            <tr> 
                                                <td align="left">  
                                                    <asp:Button ID="btnUpdate" runat="server" Text="Update" CommandName="Update" Visible='<%# !(DataItem is GridInsertionObject) %>' /> 
                                                    <asp:Button ID="btnInsert" runat="server" Text="Insert" CommandName="Insert" Visible='<%# DataItem is GridInsertionObject %>' /> 
                                                    &nbsp;  
                                                    <asp:Button ID="btnCancel" runat="server" Text="Cancel" CommandName="Cancel" CausesValidation="false" /> 
                                                </td> 
                                            </tr> 
                                        </table> 
                                    </div> 
                                </div> 
                            </div> 
                        </div> 
                    </td> 
                </tr> 
            </table> 
        </ContentTemplate> 
    </asp:UpdatePanel> 
     


    My user control code behind file.
    namespace InternalAdmin.UserControls.News  
    {  
        public partial class NewsManagementEditControl : System.Web.UI.UserControl  
        {  
            private List<OApplicationNews> ApplicationNews  
            {  
                get 
                {  
                    object o = Session["_ApplicationNews"];  
                    if (o == null)  
                        return new List<OApplicationNews>();  
                    else 
                    {  
                        return (List<OApplicationNews>)o;  
                    }  
                }  
            }  
     
            private object _dataItem = null;  
            public object DataItem  
            {  
                get 
                {  
                    return this._dataItem;  
                }  
                set 
                {  
                    this._dataItem = value;  
                }  
            }  
     
            protected void Page_Load(object sender, EventArgs e)  
            {  
            }  
     
            protected void rptApplicationList_ItemDataBound(object sender, RepeaterItemEventArgs e)  
            {  
                var data = (OApplication)e.Item.DataItem;  
                var applicationControl = (CheckBox)e.Item.FindControl("application");  
                applicationControl.Text = data.ApplicationName;  
                applicationControl.Attributes["applicationId"] = data.ApplicationId.ToString();  
     
                var applicationNewsId =  
                    ApplicationNews.Where(id => id.ApplicationId == data.ApplicationId);  
                if (applicationNewsId.Count() > 0)  
                {  
                    applicationControl.Attributes["applicationNewsId"] =  
                        applicationNewsId.Select(id => id.ApplicationNewsId).First().ToString();  
                    applicationControl.Checked = true;  
                }  
            }  
        }  
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 20 Apr 2010 Link to this post

    Hello Josh,

    Change the CommandName of btnInsert as "PerformInsert" in your user control and see whether it helps you.

    Please do let me know if you have any more queries.

    -Shinu.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Josh Sudbury
    Josh Sudbury avatar
    10 posts
    Member since:
    Apr 2010

    Posted 06 Aug 2010 Link to this post

    We ended up going another route with this, but thanks for the info, I've marked it in case I ever come across this issue again!


    Thanks!
  5. Susan Hessler
    Susan Hessler avatar
    13 posts
    Member since:
    May 2006

    Posted 27 Oct 2010 Link to this post

    I have this same problem.  I tried changing the command to PerformUpdate but that didn't work.  I am doing this in another place and it works just fine.  I have compared them multiple times and see nothing different.  I have also tried putting in breakpoints and alerts to step through but can't figure out where its going wrong.

    Any ideas on what might be happening or how to debug it?

    Thanks!
    Susan
  6. Mira
    Admin
    Mira avatar
    1124 posts

    Posted 28 Oct 2010 Link to this post

    Hello Susan,

    Please take a look at this help topic to see the correct names of the build-in commands of the grid.

    I hope it helps.

    Regards,
    Mira
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  7. Susan Hessler
    Susan Hessler avatar
    13 posts
    Member since:
    May 2006

    Posted 28 Oct 2010 Link to this post

    Unfortunately, that didn't help.  I had tried PerformInsert and when that didn't work, I thought maybe since I was updating, I'd try PerformUpdate...

    I have an onCommand javascript function in the main page (not the control's page) and have an alert to let me know that its been called, and its never called.  I also have a breakpoint in page_load that never gets triggered either. 

    Any idea on what to try next?

    OH, this is not the only user control I call from a grid on this page either.  Could that be the problem?  I just went back to make sure the first grid still worked and it is now doing the same thing.  I have also upgraded to version Q2 2010.

    Thanks!
    Susan
  8. Mira
    Admin
    Mira avatar
    1124 posts

    Posted 02 Nov 2010 Link to this post

    Hello Susan,

    Based on the supplied information, it is hard to determine what is causing the error.
    Could you please provide little bit more details on your scenario? How is the event handler of the OnCommand event attached? How are the user controls loaded? Have you ajaxified your pages?

    Sending us a sample project demonstrating the issue will be highly appreciated.

    Best wishes,
    Mira
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  9. Gábor
    Gábor avatar
    10 posts
    Member since:
    Nov 2010

    Posted 03 Nov 2010 Link to this post

    Hello guys,

    I also have a problem with the InsertCommand event not firing. My scenario is slightly different however as I dont use my own control to provide the edit form.
    My grid is very simple it only has one visible databound column which contains names -- names of funcctions on an administration page.
    The grid is not directly bounded to the database (or the OpenAccess entity model) as I would like to call the functions of the business layer for adding new records and editing etc.

    I attach below the code of a user control which contains the problematic grid:
    The ascx file:
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Functions.ascx.cs" Inherits="Xapt.AgilePoint.UI.Microsite.UserControls.Functions" %>
    <%@ Register Assembly="Xapt.General.Web" Namespace="Xapt.General.Web.UI" TagPrefix="xapt" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
      
    <div class="mediumCenter">
        <telerik:RadGrid ID="FunctionsGrid" runat="server" AutoGenerateColumns="False" 
            GridLines="None" oneditcommand="FunctionsGrid_EditCommand" onneeddatasource="FunctionsGrid_NeedDataSource" 
            OnInsertCommand="FunctionsGrid_InsertCommand" 
            onitemcommand="FunctionsGrid_ItemCommand">
            <MasterTableView CommandItemDisplay="Top" DataKeyNames="FunctionID">
            <CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>
                <Columns >
                    <telerik:GridBoundColumn HeaderText="FunctionId" 
                        UniqueName="columnFunctionId" DataField="FunctionId" Visible="false">
                        <ItemStyle HorizontalAlign="Left" />
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn HeaderText="FunctionName" 
                        UniqueName="columnFunctionName" Resizable="true" DataField="Name" 
                        ColumnEditorID="GridTextBoxColumnEditor1">
                        <ItemStyle HorizontalAlign="Left" />
                    </telerik:GridBoundColumn>
                    <telerik:GridEditCommandColumn HeaderText=""  UniqueName="EditCommandColumn" ButtonType="ImageButton">
                        <HeaderStyle Width="15%" />
                        <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    </telerik:GridEditCommandColumn>
                </Columns>
                <EditFormSettings ColumnNumber="1" >
                    <FormMainTableStyle Width="100%" />
                    <EditColumn ButtonType="ImageButton"/>
                    <FormTableButtonRowStyle HorizontalAlign="Right" />
                </EditFormSettings>     
            </MasterTableView>
        </telerik:RadGrid>
        <telerik:GridTextBoxColumnEditor ID="GridTextBoxColumnEditor1" runat="server" TextBoxStyle-Width="200px" />
    </div>
    <telerik:RadWindowManager ID="RadWindowManager1" runat="server" Modal="True" 
        Title="Test" Behavior="Default" InitialBehavior="None">
    </telerik:RadWindowManager>
    <telerik:RadWindow ID="RadWindowEditFunction" runat="server" Width="900" Height="500" Modal="true" VisibleOnPageLoad="false" OnClientClose="Window_OnClientClose">
    </telerik:RadWindow>

    The code behind (functions.ascx.cs):
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Web.UI;
    using Xapt.AgilePoint.Security;
    using Xapt.TelerikLibraries.Web;
    using Xapt.AgilePoint.BusinessLayer.Application;
    using Xapt.AgilePoint.Data.SiteContextModel;
      
    namespace Xapt.AgilePoint.UI.Microsite.UserControls
    {
        public partial class Functions : Xapt.TelerikLibraries.Web.UI.TelerikUserControl
        {
            RadSkinManager skinManager;
            UserSecurityBLC theUserSecurityBLC;
      
            #region Event handlers
      
            protected void Page_Load(object sender, EventArgs e)
            {
                Localize(Xapt.TelerikLibraries.Web.UI.LocalizableControl.RadGrid);
      
                RadAjaxManager ajaxManager = this.Page.Master.FindControl("RadAjaxManager1") as RadAjaxManager;
                ajaxManager.AjaxSettings.AddAjaxSetting(FunctionsGrid, RadWindowEditFunction);
                ajaxManager.AjaxSettings.AddAjaxSetting(FunctionsGrid, RadWindowManager1);
                ajaxManager.AjaxSettings.AddAjaxSetting(FunctionsGrid, FunctionsGrid);
                  
                //--- Set the Skin of the windows based on the current page settings
                skinManager = this.Page.Master.FindControl("RadSkinManager1") as RadSkinManager;
                RadWindowEditFunction.Skin = skinManager.Skin;
                RadWindowEditFunction.Behaviors = WindowBehaviors.Close | WindowBehaviors.Maximize | WindowBehaviors.Resize | WindowBehaviors.Move;
                FunctionsGrid.MasterTableView.EditMode = GridEditMode.InPlace;
      
                theUserSecurityBLC = BusinessLayer.BusinessLogicComponentFactory.Current.UserSecurityBLC;
            }
      
      
            protected void FunctionsGrid_EditCommand(object source, global::Telerik.Web.UI.GridCommandEventArgs e)
            {
                RadWindowEditFunction.NavigateUrl = "~/Menu/Administration/PopUps/RoleFunctionsForm.aspx?role=" +
                                                            (e.Item.DataItem as SiteFunction).Name +
                                                            "&skin=" + skinManager.Skin;
      
                RadWindowEditFunction.VisibleOnPageLoad = true;
                e.Canceled = true;
            }
      
            protected void FunctionsGrid_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
            {
                if (e.RebindReason != GridRebindReason.PostBackEvent)
                {
                    IEnumerable<SiteFunction> siteFunctions = theUserSecurityBLC.GetSiteFunctions().ToList();
                    FunctionsGrid.DataSource = siteFunctions;
                }
            }
      
            protected void FunctionsGrid_InsertCommand(object source, GridCommandEventArgs e)
            {
                //-- Code talking to the business layer comes here
                //-- This function is never called!
                return;
            }
      
            protected void FunctionsGrid_ItemCommand(object source, GridCommandEventArgs e)
            {
                //-- Catch any command here
                //-- When I click on the sumbit button in the insert line form
                //-- this function is not called either!
                return;
            }
            #endregion
        }
    }

    I am quite new with RadControls, so I'm open to any suggestions on how the grid should be configured properly for this scenario if you believe there are problems with the code.

    The version of my Telerik.Web.UI.dll is: v4.0.30319

    Regards,

    Gabor Varga
    Xapt Hungary Ltd.
  10. Mira
    Admin
    Mira avatar
    1124 posts

    Posted 03 Nov 2010 Link to this post

    Hello Gábor,

    Please take a look at the Updating values in-place and with edit forms help topic to see how the desired functionality can be implemented.

    I hope this helps.

    Kind regards,
    Mira
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  11. Gábor
    Gábor avatar
    10 posts
    Member since:
    Nov 2010

    Posted 03 Nov 2010 Link to this post

    Hi Mira,

    Thank you for your answer. I checked the topic and I will implement my InsertCommand function accordingly.

    My issue is however not how I could implement the function, but rather, that it is never called. There is a breakpoint in the funciton but it is never reached.

    The only major difference that I could see in the example solution is that they use a DataTable as there datasource, while I am using a List. Otherwise my settings are pretty much similar, and my grid look good, it works well, the only problem is that once i click the submit button, although there is a postback, no event is raised.

    Regards,

    Gabor Varga
    Xapt Hungary Ltd.
  12. Gábor
    Gábor avatar
    10 posts
    Member since:
    Nov 2010

    Posted 04 Nov 2010 Link to this post

    Hello Team,

    The problem only persists if I use the MasterPage of my site.

    If I put the grid with a ScriptManger on a plain site it fires the InsertCommand event.
    Once I copy-paste the very same grid, the datasource and the event handlers to a page which uses the MasterPage: the event handler is no longer called.

    My script manger is in the MasterPage.

    I am curiously waiting for some advice on the issue, because I am stuck with it for 3 days now, and I have no idea where the problem could be.

    Kind regards,

    Gabor
  13. Gábor
    Gábor avatar
    10 posts
    Member since:
    Nov 2010

    Posted 05 Nov 2010 Link to this post

    Hi all,

    The problem I mentioned before has been solved. The ViewState was disabled in the main form of the MasterPage which resulted in the abnormal behavior. Once I enabled the ViewState it began firing the insert events.

    Although it is not too nice to disable the ViewState entirely, for me it is still not exactly clear why it results in not firing some of the events (like InsertCommand).

    Regards,

    Gabor
  14. Mira
    Admin
    Mira avatar
    1124 posts

    Posted 08 Nov 2010 Link to this post

    Hello Gábor,

    Please take a look at the Optimizing ViewState usage help topic to see the limitations of a grid with disabled viewstate.

    I hope this helps.

    Kind regards,
    Mira
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  15. Marian
    Marian avatar
    49 posts
    Member since:
    Sep 2008

    Posted 17 Nov 2010 Link to this post

    Hi to all,
    I have similar problem as Gábor. My scenario is:
    - .NET4, Radcontrols 2010.2.929.40
    - AllowAutomaticAction = I tried both
    - NeedDatasource is used
    - EditMode="PopUp" EditFormType="Autogenerated"
    I have read document "Optimizing ViewState usage" very carefully and I found
    limitation for Popup: "custom edit forms (user control or form template)"

    I use Autogenerated Popup. Everything with edit/insert is OK if may page EnableViewState="true".
    In the case of setting the same to false - RadGrid_UpdateCommand and RadGrid_InsertCommand do
    not fire from Popup.
    Thanks fo your reply
    -Marian
  16. Mira
    Admin
    Mira avatar
    1124 posts

    Posted 22 Nov 2010 Link to this post

    Hello Marian,

    I tried to replicate the issue which you described, but to no avail.
    Attached to this message, you will find the code which I used for testing.

    Please, take a look at it and let me know if there are any differences at your end, which I may be leaving out.

    Sincerely yours,
    Mira
    the Telerik team
    Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  17. Marian
    Marian avatar
    49 posts
    Member since:
    Sep 2008

    Posted 26 Nov 2010 Link to this post

    Hello Mira,
    sorry for delayed answer. Today I inspected my problem with RadGrid_Command events. As I told if viewstate is enabled radgrid's behavior is OK. I do not use Autogenerated  columns, but construction like this:
    <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete"    UniqueName="DeleteCommandColumn" ConfirmDialogType="RadWindow" Text="Odstrániť" ConfirmTitle="Otázka" ConfirmText="Naozaj odstrániť osobu?">
    <ItemStyle Width="0" />
    </telerik:GridButtonColumn>
    If I turn viewstate to false, realy no edit/delete command is fired.
    Nevertheless I discover for me unbelievable behavior of my RadGrid. I tried to replace ImageButton with LinkButton and PushButton. Both works perfectly although viewstate is disabled. Only ImageButton does not fire relevant events.
    -Marian
  18. Mira
    Admin
    Mira avatar
    1124 posts

    Posted 30 Nov 2010 Link to this post

    Hello Marian,

    The desired functionality cannot be implemented when the viewstate of the grid is disabled.
    Excuse us for any inconveniences caused.

    Best wishes,
    Mira
    the Telerik team
    Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  19. Josh
    Josh avatar
    3 posts
    Member since:
    May 2012

    Posted 06 Jun 2012 Link to this post

    I had a question but have since resolved it by just redoing the control on the page and everything is working now.  I didn't see a way to delete my post so....
  20. Ed
    Ed avatar
    1 posts
    Member since:
    Sep 2008

    Posted 17 Jul 2012 Link to this post

    I have a similar issue that I can't figure out. The difference is that while the OnUpdateCommand event is not firing, the OnInsertCommand event IS firing.

    Here is the basic page contents:
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="TVProductSelector.WebForm1" %>
     
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
            </telerik:RadScriptManager>
            <asp:SqlDataSource ID="SqlDataSource_SelectedItems" runat="server" ConnectionString="Data Source=xxxxx;Initial Catalog=xxxxx;Integrated Security=True"
                SelectCommand="SELECT * FROM [vPF_OrderItems] WHERE [pfOrderID] = @pfOrderID ORDER BY [item_nbr]"
                ProviderName="System.Data.SqlClient">
                <SelectParameters>
                    <asp:Parameter DefaultValue="64" Name="pfOrderID" />
                </SelectParameters>
            </asp:SqlDataSource>
            <telerik:RadGrid ID="RadGrid_SelectedItems" runat="server" AllowPaging="True" DataSourceID="SqlDataSource_SelectedItems"
                GridLines="None" PageSize="15" AllowMultiRowSelection="True" OnInsertCommand="RadGrid_SelectedItems_InsertCommand"
                OnUpdateCommand="RadGrid_SelectedItems_UpdateCommand" AutoGenerateColumns="False"
                CssClass="TrueValue_tcStandardInput" OnItemCommand="RadGrid_SelectedItems_ItemCommand"
                EnableViewState="true">
                <MasterTableView DataSourceID="SqlDataSource_SelectedItems" PageSize="10" ClientDataKeyNames="ID"
                    AllowAutomaticDeletes="false" AllowAutomaticInserts="false" AllowAutomaticUpdates="false"
                    DataKeyNames="ID" CommandItemDisplay="TopAndBottom">
                    <CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>
                    <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
                    </RowIndicatorColumn>
                    <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
                    </ExpandCollapseColumn>
                    <Columns>
                        <telerik:GridEditCommandColumn ButtonType="ImageButton" FilterControlAltText="Filter EditCommandColumn column">
                        </telerik:GridEditCommandColumn>
                        <telerik:GridTemplateColumn DataField="ID" FilterControlAltText="Filter column column"
                            HeaderText="ID" UniqueName="column" Visible="False">
                            <EditItemTemplate>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>'></asp:Label>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn DataField="item_nbr" DataType="System.Double" FilterControlAltText="Filter item_nbr column"
                            HeaderText="Sku" SortExpression="item_nbr" UniqueName="item_nbr">
                            <EditItemTemplate>
                                <asp:TextBox ID="item_nbrTextBox" runat="server" Enabled="false" CssClass="tb200"
                                    Text='<%# Bind("item_nbr") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="item_nbrLabel" runat="server" Text='<%# Eval("item_nbr") %>'></asp:Label>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridImageColumn DataImageUrlFields="Item_nbr" DataImageUrlFormatString="https://images.truevalue.com/getimage.asp?NoImageType=1&;ColorImageSize=1&LineArtImageSize=2&id={0}&ImageType=1"
                            FilterControlAltText="Filter column column" HeaderText="Thumbnail" ImageHeight="25px"
                            ImageWidth="25px" UniqueName="thumbnail">
                            <ItemStyle HorizontalAlign="Center" />
                        </telerik:GridImageColumn>
                        <telerik:GridTemplateColumn DataField="manufacturer" FilterControlAltText="Filter manufacturer column"
                            HeaderText="Manufacturer" SortExpression="manufacturer" UniqueName="Manufacturer">
                            <ItemTemplate>
                                <asp:Label ID="Label_Manufacturer" runat="server" Text='<%# Eval("manufacturer") %>'></asp:Label>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn DataField="model" FilterControlAltText="Filter model column"
                            HeaderText="Model" SortExpression="model" UniqueName="model">
                            <EditItemTemplate>
                                <asp:TextBox ID="modelTextBox" runat="server" CssClass="tb200" Text='<%# Bind("model") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="modelLabel" runat="server" Text='<%# Eval("model") %>'></asp:Label>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn DataField="description" FilterControlAltText="Filter description column"
                            HeaderText="Description" SortExpression="description" UniqueName="description">
                            <EditItemTemplate>
                                <asp:TextBox ID="descriptionTextBox" runat="server" CssClass="tb800" Text='<%# Bind("description") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="descriptionLabel" runat="server" Text='<%# Eval("description") %>'></asp:Label>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn DataField="bullet_1" FilterControlAltText="Filter bullet_1 column"
                            HeaderText="Bullet 1" SortExpression="bullet_1" UniqueName="bullet_1">
                            <EditItemTemplate>
                                <asp:TextBox ID="bullet_1TextBox" runat="server" CssClass="tb800" Text='<%# Bind("bullet_1") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="bullet_1Label" runat="server" Text='<%# Eval("bullet_1") %>'></asp:Label>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn DataField="bullet_2" FilterControlAltText="Filter bullet_2 column"
                            HeaderText="Bullet 2" SortExpression="bullet_2" UniqueName="bullet_2">
                            <EditItemTemplate>
                                <asp:TextBox ID="bullet_2TextBox" runat="server" CssClass="tb800" Text='<%# Bind("bullet_2") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="bullet_2Label" runat="server" Text='<%# Eval("bullet_2") %>'></asp:Label>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn DataField="bullet_3" FilterControlAltText="Filter bullet_3 column"
                            HeaderText="Bullet 3" SortExpression="bullet_3" UniqueName="bullet_3">
                            <EditItemTemplate>
                                <asp:TextBox ID="bullet_3TextBox" runat="server" CssClass="tb800" Text='<%# Bind("bullet_3") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="bullet_3Label" runat="server" Text='<%# Eval("bullet_3") %>'></asp:Label>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn DataField="bullet_4" FilterControlAltText="Filter bullet_4 column"
                            HeaderText="Bullet 4" SortExpression="bullet_4" UniqueName="bullet_4" Visible="False">
                            <EditItemTemplate>
                                <asp:TextBox ID="bullet_4TextBox" runat="server" CssClass="tb800" Text='<%# Bind("bullet_4") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="bullet_4Label" runat="server" Text='<%# Eval("bullet_4") %>'></asp:Label>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn DataField="bullet_5" FilterControlAltText="Filter bullet_5 column"
                            HeaderText="Bullet 5" SortExpression="bullet_5" UniqueName="bullet_5" Visible="False">
                            <EditItemTemplate>
                                <asp:TextBox ID="bullet_5TextBox" runat="server" CssClass="tb800" Text='<%# Bind("bullet_5") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="bullet_5Label" runat="server" Text='<%# Eval("bullet_5") %>'></asp:Label>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn DataField="bullet_6" FilterControlAltText="Filter bullet_6 column"
                            HeaderText="Bullet 6" SortExpression="bullet_6" UniqueName="bullet_6" Visible="False">
                            <EditItemTemplate>
                                <asp:TextBox ID="bullet_6TextBox" runat="server" CssClass="tb800" Text='<%# Bind("bullet_6") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="bullet_6Label" runat="server" Text='<%# Eval("bullet_6") %>'></asp:Label>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn DataField="bullet_7" FilterControlAltText="Filter bullet_7 column"
                            HeaderText="Bullet 7" SortExpression="bullet_7" UniqueName="bullet_7" Visible="False">
                            <EditItemTemplate>
                                <asp:TextBox ID="bullet_7TextBox" runat="server" CssClass="tb800" Text='<%# Bind("bullet_7") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="bullet_7Label" runat="server" Text='<%# Eval("bullet_7") %>'></asp:Label>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn DataField="bullet_8" FilterControlAltText="Filter bullet_8 column"
                            HeaderText="Bullet 8" SortExpression="bullet_8" UniqueName="bullet_8" Visible="False">
                            <EditItemTemplate>
                                <asp:TextBox ID="bullet_8TextBox" runat="server" CssClass="tb800" Text='<%# Bind("bullet_8") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="bullet_8Label" runat="server" Text='<%# Eval("bullet_8") %>'></asp:Label>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn DataField="StorePrice" DataType="System.Double" FilterControlAltText="Filter StorePrice column"
                            HeaderText="Suggested Retail" SortExpression="StorePrice" UniqueName="StorePrice"
                            Visible="False">
                            <EditItemTemplate>
                                <asp:TextBox ID="StorePriceTextBox" runat="server" CssClass="tb200" Text='<%# Bind("StorePrice") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="StorePriceLabel" runat="server" Text='<%# Eval("StorePrice") %>'></asp:Label>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn DataField="Quantity" DataType="System.Double" FilterControlAltText="Filter Quantity column"
                            HeaderText="Quantity" SortExpression="Quantity" UniqueName="Quantity" Visible="False">
                            <EditItemTemplate>
                                <telerik:RadNumericTextBox ID="RadNumericTextBox_Quantity" runat="server" DbValue='<%# Eval("Quantity") %>'
                                    MinValue="1" MaxValue="50" IncrementSettings-Step="1">
                                </telerik:RadNumericTextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="QuantityLabel" runat="server" Text='<%# Eval("Quantity") %>'></asp:Label>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" FilterControlAltText="Filter column column"
                            Text="Delete" UniqueName="column2">
                        </telerik:GridButtonColumn>
                    </Columns>
                </MasterTableView>
                <FilterMenu EnableImageSprites="False">
                </FilterMenu>
                <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
                </HeaderContextMenu>
            </telerik:RadGrid>
        </div>
        </form>
    </body>
    </html>

    Adding a break point to the  RadGrid_SelectedItems_InsertCommand and RadGrid_SelectedItems_UpdateCommand show that the Insert command is firing while the Update command is not. I can understand how the outer item commands (Edit and Delete) fire while the inner (Insert and Update) do not. But I do not understand how one inner command works and the other does not. Here is the basic code behind:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Web.UI;
    using System.Data.SqlClient;
    using System.Configuration;
    using System.Data;
    using System.Net;
    using System.IO;
     
    namespace TVProductSelector
    {
        public partial class WebForm1 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                    SqlDataSource_SelectedItems.SelectParameters["pfOrderID"].DefaultValue = "87a94fbd57f14adf88b3e5feb54f3612";
            }
     
            protected void RadGrid_SelectedItems_ItemCommand(object sender, GridCommandEventArgs e)
            {
     
            }
     
            protected void RadGrid_SelectedItems_InsertCommand(object sender, GridCommandEventArgs e)
            {
     
            }
     
            protected void RadGrid_SelectedItems_UpdateCommand(object sender, GridCommandEventArgs e)
            {
     
            }
        }
    }

  21. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 20 Jul 2012 Link to this post

    Hi,

    I went through the provided code and it looks correct.Therefore, I suggest that you send us a sample project illustrating you scenario and the issue, which will help us to find the source of the problem. Thus we could debug it locally and turn back to you with a proper resolution.

    Regards,
    Pavlina
    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.
  22. chad
    chad avatar
    3 posts
    Member since:
    Mar 2016

    Posted 09 Mar in reply to Pavlina Link to this post

    RadGrid1_ItemInserted doesnt get fired when calling from OnItemInserted. I want to show client error message (exception message). Currently with below code it simply won't insert data if i enter wrong data type value in any of radgrid column but wouldn't throw error message too. I want to show user a error message. Please help me. Thanks in advance.

     

     

     

     

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="HPPRawData.aspx.cs" Inherits="HPPDemo.HPPRawData" %>

    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

    <!DOCTYPE html>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>

                <telerik:RadGrid ID="RadGrid1" AutoGenerateColumns="False"
                    AllowPaging="True" runat="server" OnItemDataBound="OnItemDataBoundHandler"
                    DataSourceID="SqlDataSource1" FilterType="HeaderContext" EnableHeaderContextFilterMenu="True" EnableHeaderContextMenu="True" DataKeyNames="ID" OnItemInserted="RadGrid1_ItemInserted"
                    ShowStatusBar="True" GroupPanelPosition="Top" CellSpacing="-1" GridLines="Both" AllowSorting="True" AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True" AutoGenerateDeleteColumn="True" AutoGenerateEditColumn="True">
                    <GroupingSettings CollapseAllTooltip="Collapse all groups"></GroupingSettings>
                    <MasterTableView ShowFooter="false" EditMode="InPlace" CommandItemDisplay="TopAndBottom" DataSourceID="SqlDataSource1" DataKeyNames="ID">
                        <RowIndicatorColumn Visible="False">
                        </RowIndicatorColumn>
                        <ExpandCollapseColumn Created="True">
                        </ExpandCollapseColumn>
                        <Columns>
                            <telerik:GridBoundColumn DataField="ID" DataType="System.Int32" FilterControlAltText="Filter ID column" HeaderText="ID" ReadOnly="True" SortExpression="ID" UniqueName="ID">
                            </telerik:GridBoundColumn>
                           <%-- <telerik:GridBoundColumn DataField="Year" DataType="System.Int32" FilterControlAltText="Filter Year column" HeaderText="Year" SortExpression="Year" UniqueName="Year">
                              </telerik:GridBoundColumn>--%>




                            <telerik:GridTemplateColumn HeaderText="Year" SortExpression="Year"
                            UniqueName="Year" EditFormColumnIndex="1" Visible="True">
                            <HeaderStyle Width="80px"></HeaderStyle>
                            <ItemTemplate>
                                <asp:Label runat="server" ID="Year" Text='<%# Eval("Year") %>'></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <br />
                                <asp:TextBox runat="server" ID="tbReorderLevel" Text='<%# Bind("Year") %>'></asp:TextBox>
                                <div style="color: #e93100;">
                                    
                                </div>
                                <asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Invalid input"
                                    ControlToValidate="tbReorderLevel" OnServerValidate="CustomValidator1_ServerValidate">
                                </asp:CustomValidator>
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>







                           
                            <telerik:GridTemplateColumn UniqueName="WeekEnding" HeaderText="WeekEnding"
                                ItemStyle-Width="400px">
                                <ItemTemplate>
                                    <%#DataBinder.Eval(Container.DataItem, "WeekEnding")%>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <telerik:RadDatePicker ID="picker1" runat="server" DbSelectedDate='<%# Bind("WeekEnding") %>'
                                        DefaultInsertValue="Today" Culture="Swedish (Sweden)">
                                    </telerik:RadDatePicker>
                                </EditItemTemplate>
                                <ItemStyle Width="400px"></ItemStyle>
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn UniqueName="RunDate" HeaderText="RunDate"
                                ItemStyle-Width="400px">
                                <ItemTemplate>
                                    <%#DataBinder.Eval(Container.DataItem, "RunDate")%>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <telerik:RadDatePicker ID="picker2" runat="server" DbSelectedDate='<%# Bind("RunDate") %>'
                                        DefaultInsertValue="Today" Culture="Swedish (Sweden)">
                                    </telerik:RadDatePicker>
                                </EditItemTemplate>
                                <ItemStyle Width="400px"></ItemStyle>
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn UniqueName="SKU" HeaderText="Supplier" SortExpression="SKU"
                                ItemStyle-Width="400px">
                                <FooterTemplate>
                                    Template footer
                                </FooterTemplate>
                                <FooterStyle VerticalAlign="Middle" HorizontalAlign="Center" />
                                <ItemTemplate>
                                    <%#DataBinder.Eval(Container.DataItem, "SKU")%>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <telerik:RadComboBox runat="server" ID="RadComboBox1" EnableLoadOnDemand="True" DataTextField="item_No_Name"
                                        DataValueField="item_No" OnItemsRequested="RadComboBoxProduct_ItemsRequested"
                                        HighlightTemplatedItems="true" Height="140px" Width="220px" DropDownWidth="420px" Filter="StartsWith"
                                        DataSourceID="SqlDataSource3" SelectedValue='<%#Bind("SKU") %>'>
                                    </telerik:RadComboBox>

                                </EditItemTemplate>

                                <ItemStyle Width="400px"></ItemStyle>
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn UniqueName="ExpirationDate" HeaderText="ExpirationDate"
                                ItemStyle-Width="400px">
                                <ItemTemplate>
                                    <%#DataBinder.Eval(Container.DataItem, "ExpirationDate")%>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <telerik:RadDatePicker ID="picker3" runat="server" DataSourceID="SqlDataSource1" DbSelectedDate='<%# Bind("ExpirationDate") %>'
                                        DefaultInsertValue="Today" Culture="Swedish (Sweden)">
                                    </telerik:RadDatePicker>
                                </EditItemTemplate>
                                <ItemStyle Width="400px"></ItemStyle>
                            </telerik:GridTemplateColumn>

                            <telerik:GridBoundColumn DataField="UnitsProduced" DataType="System.Int32" FilterControlAltText="Filter UnitsProduced column" HeaderText="UnitsProduced" SortExpression="UnitsProduced" UniqueName="UnitsProduced">
                            <ColumnValidationSettings EnableRequiredFieldValidation="true" EnableModelErrorMessageValidation="true">
                                    <RequiredFieldValidator ForeColor="Red" ErrorMessage="This field is required"></RequiredFieldValidator>
                                    <ModelErrorMessage BackColor="Red" />
                                </ColumnValidationSettings>
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="PackagesPerCase" DataType="System.Int32" FilterControlAltText="Filter PackagesPerCase column" HeaderText="PackagesPerCase" SortExpression="PackagesPerCase" UniqueName="PackagesPerCase">
                            <ColumnValidationSettings EnableRequiredFieldValidation="true" EnableModelErrorMessageValidation="true">
                                    <RequiredFieldValidator ForeColor="Red" ErrorMessage="This field is required"></RequiredFieldValidator>
                                    <ModelErrorMessage BackColor="Red" />
                                </ColumnValidationSettings>
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="TotalPackages" DataType="System.Int32" FilterControlAltText="Filter TotalPackages column" HeaderText="TotalPackages" SortExpression="TotalPackages" UniqueName="TotalPackages">
                            <ColumnValidationSettings EnableRequiredFieldValidation="true" EnableModelErrorMessageValidation="true">
                                    <RequiredFieldValidator ForeColor="Red" ErrorMessage="This field is required"></RequiredFieldValidator>
                                    <ModelErrorMessage BackColor="Red" />
                                </ColumnValidationSettings>
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Pre_HPPLeaker_LoosePackaging" DataType="System.Int32" FilterControlAltText="Filter Pre_HPPLeaker_LoosePackaging column" HeaderText="Pre_HPPLeaker_LoosePackaging" SortExpression="Pre_HPPLeaker_LoosePackaging" UniqueName="Pre_HPPLeaker_LoosePackaging">
                           <ColumnValidationSettings EnableRequiredFieldValidation="true" EnableModelErrorMessageValidation="true">
                                    <RequiredFieldValidator ForeColor="Red" ErrorMessage="This field is required"></RequiredFieldValidator>
                                    <ModelErrorMessage BackColor="Red" />
                                </ColumnValidationSettings>
                                 </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Post_HPP_Leaker_LoosePackaging" DataType="System.Int32" FilterControlAltText="Filter Post_HPP_Leaker_LoosePackaging column" HeaderText="Post_HPP_Leaker_LoosePackaging" SortExpression="Post_HPP_Leaker_LoosePackaging" UniqueName="Post_HPP_Leaker_LoosePackaging">
                            <ColumnValidationSettings EnableRequiredFieldValidation="true" EnableModelErrorMessageValidation="true">
                                    <RequiredFieldValidator ForeColor="Red" ErrorMessage="This field is required"></RequiredFieldValidator>
                                    <ModelErrorMessage BackColor="Red" />
                                </ColumnValidationSettings>
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="LineageLot" DataType="System.Int32" FilterControlAltText="Filter LineageLot column" HeaderText="LineageLot" SortExpression="LineageLot" UniqueName="LineageLot">
                            <ColumnValidationSettings EnableRequiredFieldValidation="true" EnableModelErrorMessageValidation="true">
                                    <RequiredFieldValidator ForeColor="Red" ErrorMessage="This field is required"></RequiredFieldValidator>
                                    <ModelErrorMessage BackColor="Red" />
                                </ColumnValidationSettings>
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="LotCode3" FilterControlAltText="Filter LotCode3 column" HeaderText="LotCode3" SortExpression="LotCode3" UniqueName="LotCode3">
                           <ColumnValidationSettings EnableRequiredFieldValidation="true" EnableModelErrorMessageValidation="true">
                                    <RequiredFieldValidator ForeColor="Red" ErrorMessage="This field is required"></RequiredFieldValidator>
                                    <ModelErrorMessage BackColor="Red" />
                                </ColumnValidationSettings>
                                 </telerik:GridBoundColumn>




                            <%--  <telerik:GridTemplateColumn HeaderText="Machine_Name" ItemStyle-Width="240px">
                            <ItemTemplate>
                                <%#DataBinder.Eval(Container.DataItem, "Machine_Name")%>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <telerik:RadDropDownList RenderMode="Lightweight" runat="server" ID="RadDropDownList1"  SelectedValue='<%#Bind("SKU") %>'>
                                        <Items>
                                            <telerik:DropDownListItem Text="Machineon" />
                                            <telerik:DropDownListItem Text="MachineTw" />
                                        </Items>
                                </telerik:RadDropDownList>
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>--%>


                            <telerik:GridTemplateColumn HeaderText="Machine_Name" ItemStyle-Width="240px">
                                <ItemTemplate>
                                    <%#DataBinder.Eval(Container.DataItem, "Machine_Name")%>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <telerik:RadComboBox runat="server" ID="RadComboBox8" DataTextField="Machine_Name" RenderMode="Lightweight"
                                        DataValueField="Machine_Name" DataSourceID="SqlDataSource2" SelectedValue='<%#Bind("Machine_Name") %>'>
                                    </telerik:RadComboBox>
                                </EditItemTemplate>
                            </telerik:GridTemplateColumn>



                            <%-- %>  <telerik:GridBoundColumn DataField="Machine_Name" FilterControlAltText="Filter Machine_Name column" HeaderText="Machine_Name" SortExpression="Machine_Name" UniqueName="Machine_Name">
                            </telerik:GridBoundColumn>--%>

                            <telerik:GridBoundColumn DataField="Date_Created" FilterControlAltText="Filter Date_Created column" HeaderText="Date_Created" SortExpression="Date_Created" UniqueName="Date_Created">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Date_Modified" FilterControlAltText="Filter Date_Modified column" HeaderText="Date_Modified" SortExpression="Date_Modified" UniqueName="Date_Modified">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Modified_by" FilterControlAltText="Filter Modified_by column" HeaderText="Modified_by" SortExpression="Modified_by" UniqueName="Modified_by">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Item_Name" Display="false" Visible="false" FilterControlAltText="Filter Item_Name column" HeaderText="Item_Name" SortExpression="Item_Name" UniqueName="Item_Name">
                            </telerik:GridBoundColumn>
                        </Columns>
                    </MasterTableView>
                </telerik:RadGrid>

                <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:HPPConnectionString %>" SelectCommand="select distinct item_no,item_No_Name from dimitem"></asp:SqlDataSource>

                <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:HPPConnectionString %>" SelectCommand="select distinct machine_name from HPP_RAW_DATA where Machine_Name is not null"></asp:SqlDataSource>

            </div>
            <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>

            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:HPPConnectionString %>"
                SelectCommand="SELECT * FROM [dbo].[vw_HPPRaw]"
                DeleteCommandType="StoredProcedure"
                DeleteCommand="HPPRawData_DeleteRecord"
                InsertCommandType="StoredProcedure"
                InsertCommand="HPPRawData_InsertRecord"
                UpdateCommandType="StoredProcedure"
                UpdateCommand="HPPRawData_UpdateRecord">
                <DeleteParameters>
                    <asp:Parameter Name="ID" Type="Int32" />
                </DeleteParameters>
                <InsertParameters>
                    <asp:Parameter Name="Year" Type="Int32" />
                    <asp:Parameter Name="WeekEnding" Type="DateTime" />
                    <asp:Parameter Name="RunDate" Type="DateTime" />
                    <asp:Parameter Name="SKU" Type="String" />
                    <asp:Parameter Name="ExpirationDate" Type="DateTime" />
                    <asp:Parameter Name="UnitsProduced" Type="Int32" />
                    <asp:Parameter Name="PackagesPerCase" Type="Int32" />
                    <asp:Parameter Name="TotalPackages" Type="Int32" />
                    <asp:Parameter Name="Pre_HPPLeaker_LoosePackaging" Type="Int32" />
                    <asp:Parameter Name="Post_HPP_Leaker_LoosePackaging" Type="Int32" />
                    <asp:Parameter Name="LineageLot" Type="Int32" />
                    <asp:Parameter Name="LotCode3" Type="String" />
                    <asp:Parameter Name="Machine_Name" Type="String" />
                    <asp:Parameter Name="Date_Created" Type="DateTime" />
                    <asp:Parameter Name="Date_Modified" Type="DateTime" />
                    <asp:Parameter Name="Modified_by" Type="String" />
                    <asp:Parameter Name="Item_Name" Type="String" />
                </InsertParameters>
                <UpdateParameters>
                    <asp:Parameter Name="ID" Type="Int32" />
                    <asp:Parameter Name="Year" Type="Int32" />
                    <asp:Parameter Name="WeekEnding" Type="DateTime" />
                    <asp:Parameter Name="RunDate" Type="DateTime" />
                    <asp:Parameter Name="SKU" Type="String" />
                    <asp:Parameter Name="ExpirationDate" Type="DateTime" />
                    <asp:Parameter Name="UnitsProduced" Type="Int32" />
                    <asp:Parameter Name="PackagesPerCase" Type="Int32" />
                    <asp:Parameter Name="TotalPackages" Type="Int32" />
                    <asp:Parameter Name="Pre_HPPLeaker_LoosePackaging" Type="Int32" />
                    <asp:Parameter Name="Post_HPP_Leaker_LoosePackaging" Type="Int32" />
                    <asp:Parameter Name="LineageLot" Type="Int32" />
                    <asp:Parameter Name="LotCode3" Type="String" />
                    <asp:Parameter Name="Machine_Name" Type="String" />
                    <asp:Parameter Name="Date_Created" Type="DateTime" />
                    <asp:Parameter Name="Date_Modified" Type="DateTime" />
                    <asp:Parameter Name="Modified_by" Type="String" />
                    <asp:Parameter Name="Item_Name" Type="String" />
                </UpdateParameters>

            </asp:SqlDataSource>
        </form>
    </body>
    </html>

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

    Code behind file is below :

     

     

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Collections;
    using Telerik.Web.UI;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;

    namespace HPPDemo
    {
        public partial class HPPRawData : System.Web.UI.Page
        {
           
            protected void OnItemDataBoundHandler(object sender, GridItemEventArgs e)
            {
                /*  if (e.Item.IsInEditMode)
                  {
                      GridEditableItem item = (GridEditableItem)e.Item;
                      if (!(e.Item is IGridInsertItem))
                      {
                          RadComboBox combo = (RadComboBox)item.FindControl("RadComboBox1");
                          RadComboBoxItem selectedItem = new RadComboBoxItem();
                          selectedItem.Text = ((DataRowView)e.Item.DataItem)["Customer_Name"].ToString();
                          selectedItem.Value = ((DataRowView)e.Item.DataItem)["Customer_Name_No"].ToString();
                          selectedItem.Attributes.Add("Account_Name", ((DataRowView)e.Item.DataItem)["Account_Name"].ToString());
                          combo.Items.Add(selectedItem);
                          selectedItem.DataBind();
                          Session["Customer_Name_No"] = selectedItem.Value;
                      }
                  }*/
            }
            protected void RadComboBoxProduct_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
            {
                string sqlSelectCommand = "SELECT distinct item_No_Name from [dbo].[dimitem] WHERE [item_No_Name] LIKE @text + '%'";

                SqlDataAdapter adapter = new SqlDataAdapter(sqlSelectCommand,
                ConfigurationManager.ConnectionStrings["HPPConnectionString"].ConnectionString);
                adapter.SelectCommand.Parameters.AddWithValue("@text", e.Text);
                DataTable dataTable = new DataTable();
                adapter.Fill(dataTable);
                RadComboBox RadComboBoxProduct = (RadComboBox)sender;

                foreach (DataRow dataRow in dataTable.Rows)
                {
                    RadComboBoxItem item = new RadComboBoxItem();

                    item.Text = (string)dataRow["item_No_Name"];
                    item.Value = dataRow["item_No_Name"].ToString();

                    RadComboBoxProduct.Items.Add(item);

                    item.DataBind();
                }
            }
             protected void CustomValidator1_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)
            {
                if (args.Value.StartsWith("4"))
                {
                    args.IsValid = false;
                }
            }
             private string gridMessage = null;
             private void SetMessage(string message)
             {
                 gridMessage = message;
             }
            
             protected void RadGrid1_ItemInserted(object source, GridInsertedEventArgs e)
             {
                 if (e.Exception != null)
                 {
                     e.ExceptionHandled = true;
                     SetMessage("Product cannot be inserted. Reason: " + e.Exception.Message);
                 }
                 else
                 {
                     SetMessage("New product is inserted!");
                 }
             }
        /*    protected void OnSelectedIndexChangedHandler(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
            {
                Session["item_NO_Name"] = e.Value;
            }
    */

        }
    }

  23. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 14 Mar Link to this post

    Hello,

    Instead of using OnItemInserted try to wire InsertCommand and follow the help article below which elaborates on inserting values:
    http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/data-editing/insert-records/inserting-values-using-inplace-and-editforms-modes

    Additionally, after you are inserting values manually you should set AllowAutomaticInserts property to false.

    Regards,
    Pavlina
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017