Update events not firing

13 posts, 0 answers
  1. ConsumentenClaim
    ConsumentenClaim avatar
    14 posts
    Member since:
    Oct 2010

    Posted 04 Dec 2011 Link to this post

    Hi,

    I have been trying to add a edit functionality to a grid but the update events are not firing at all. Even the OnItemCommand, it fires with the CommandName "Edit" when you click the edit button. However, when you click Update, the event doesn't fire up.

    I tried a few different codes (available on the forums) but no luck, this is my final code (using <FormTemplate>).

    I want to manually update fields using my dal project.

    <telerik:RadGrid ID="trgMaatschappijID" runat="server" AllowPaging="true" AllowSorting="True" GridLines="None" Culture="Dutch (Netherlands)" OnItemDataBound="trgMaatschappijID_ItemDataBound"
        AutoGenerateColumns="false" OnNeedDataSource="trgMaatschappijID_NeedDataSource" OnItemCommand="trgMaatschappijID_Item">
        <MasterTableView AllowMultiColumnSorting="false" AllowFilteringByColumn="true" DataKeyNames="MaatschappijId" EditMode="EditForms">
            <Columns>
                <telerik:GridEditCommandColumn ButtonType="LinkButton" UniqueName="EditCommandColumn" EditText="Bewerken" />
                <telerik:GridBoundColumn DataField="Maatschappij" HeaderText="Maatschappij" />
                <telerik:GridBoundColumn DataField="AantalProducten" HeaderText="Aantal Producten" ReadOnly="true" />
            </Columns>
            <EditFormSettings EditFormType="Template" CaptionDataField="MaatschappijId" CaptionFormatString="Bewerking van maatschappij met ID: {0}" ColumnNumber="1">
                <%--<EditColumn UpdateText="Opslaan" CancelText="Annuleren" UniqueName="EditCommandColumn1" />--%>
                <FormTemplate>
                    <table border="0" cellpadding="2">
                        <tr>
                            <td>Naam van maatschappij :</td>
                            <td>
                                <asp:TextBox runat="server" ID="txtMaatschappijID" Text='<%# Bind("Maatschappij") %>' />
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <asp:LinkButton ID="btnOpslaanID" CommandName="Update" Text="Opslaan" runat="server" />
                            </td>
                        </tr>
                    </table>
     
                </FormTemplate>
            </EditFormSettings>
        </MasterTableView>
        <SortingSettings SortedBackColor="Azure" EnableSkinSortStyles="false" SortToolTip="Klik hier om te sorteren" />
        <PagerStyle Mode="NextPrevAndNumeric" Position="Bottom" />
        <HeaderStyle Width="100px" />
    </telerik:RadGrid>
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 04 Dec 2011 Link to this post

    Hello,

    I tried the same scenario which worked as expected in my end. Here is the sample code.
    C#:
    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
            if (e.CommandName == RadGrid.UpdateCommandName)
            {//your code
            }
    }
    Also check the following help documentation.
    Automatic DataSource operations

    -Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. ConsumentenClaim
    ConsumentenClaim avatar
    14 posts
    Member since:
    Oct 2010

    Posted 06 Dec 2011 Link to this post

    The event is only firing when I click the "Edit" button, the e.CommandName contains the "Edit" value. Whenever I click the Save button when I am in the edit mode, the event doesn't get fired.

    I read on other forum threads that it also could be a binding problem. Can you check my OnNeedDataSource event please:

    (Request.Params["maatschappijid"] is always null, I want to add this functionality later..., but for now, it's always null)

    protected void trgMaatschappijID_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
            {
                if (Request.Params["maatschappijid"] != null)
                {
                    int maatschappijid = Convert.ToInt32(Request.Params["maatschappijid"]);
     
                    var producten = ccWebsite.Aanbieder.AanbiederProductBase.SelectAll().Where(x => x.Distributiestatus != 3 && x.MaatschappijId == maatschappijid);
     
                    pnlMaatschappijID.Visible = false;
                }
                else
                {
                    var product = from products in ccWebsite.Aanbieder.AanbiederProductBase.SelectAll()
                                  group products by products.MaatschappijId into g
                                  select new
                                  {
                                      MaatschappijId = g.Key,
                                      AantalProducten = g.Count()
                                  };
     
                    var result = from p in product
                                 join m in ccWebsite.Aanbieder.Aanbieder_MaatschappijBase.SelectAll()
                                 on p.MaatschappijId equals m.MaatschappijId
                                 select new
                                 {
                                     Maatschappij = m.Naam,
                                     AantalProducten = p.AantalProducten,
                                     MaatschappijId = m.MaatschappijId
                                 };
     
                    trgMaatschappijID.DataSource = result;
                    pnlMaatschappijID.Visible = true;
                }

  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 06 Dec 2011 Link to this post

    Hello,

    Try the following code.
    C#:
    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
     if (e.CommandName == "Update")
     {//code
     }
    }
    Also check the following demo which implements the same.
    Grid / Form Template Edit Form

    -Shinu.
  6. ConsumentenClaim
    ConsumentenClaim avatar
    14 posts
    Member since:
    Oct 2010

    Posted 06 Dec 2011 Link to this post

    Hi,

    The event is not firing at all.

    Unfortunately I don't know if this is a bug or it's something at my side.
  7. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 08 Dec 2011 Link to this post

    Hello,

    Note that automatic data source operations only work when binding the grid to a declarative data source using the DataSourceID property of the grid.
    If you are using NeedDataSource you should handle the data editing manually as shown in the following online resources:
    http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/entityframeworkcrud/defaultcs.aspx
    http://www.telerik.com/help/aspnet-ajax/grid-updating-values-usercontrol-formtemplate.html
    http://www.telerik.com/help/aspnet-ajax/grid-inserting-values-usercontrol-formtemplate.html

    Greetings,
    Maria Ilieva
    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
  8. Pablo
    Pablo avatar
    10 posts
    Member since:
    Oct 2012

    Posted 08 Dec 2011 Link to this post

    Check this example: http://beecy.net/post/2009/01/07/telerik-radgrid-formtemplate-codebehind.aspx. It seems that is what you want to accomplish
  9. ConsumentenClaim
    ConsumentenClaim avatar
    14 posts
    Member since:
    Oct 2010

    Posted 09 Dec 2011 Link to this post

    Hi,

    That is the example I used. Here is the complete code, can anyone verify it's working at your side?

    ASCX
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Edit.ascx.cs" Inherits="SitefinityWebApp.Modules.ConsumentenClaim.BackEnd.Aanbieder.Edit" %>
     
    <asp:Panel runat="server" ID="pnlMaatschappijID">
        <telerik:RadGrid ID="trgMaatschappijID" runat="server" AllowPaging="true" AllowSorting="True" GridLines="None" Culture="Dutch (Netherlands)"
            AutoGenerateColumns="false" OnNeedDataSource="trgMaatschappijID_NeedDataSource" OnItemUpdated="trgMaatschappijID_Item"> <%--OnUpdateCommand="trgMaatschappijID_Item"--%>
            <MasterTableView AllowMultiColumnSorting="false" AllowFilteringByColumn="true" DataKeyNames="MaatschappijId" EditMode="EditForms">
                <Columns>
                    <telerik:GridEditCommandColumn ButtonType="LinkButton" UniqueName="EditCommandColumn" EditText="Bewerken" />
                    <telerik:GridBoundColumn DataField="Maatschappij" HeaderText="Maatschappij" />
                    <telerik:GridBoundColumn DataField="AantalProducten" HeaderText="Aantal Producten" ReadOnly="true" />
                </Columns>
                <EditFormSettings EditFormType="Template" CaptionDataField="MaatschappijId" CaptionFormatString="Bewerking van maatschappij met ID: {0}" ColumnNumber="1">
                    <%--<EditColumn UpdateText="Opslaan" CancelText="Annuleren" UniqueName="EditCommandColumn1" />--%>
                    <FormTemplate>
                        <table border="0" cellpadding="2">
                            <tr>
                                <td>Naam van maatschappij :</td>
                                <td>
                                    <asp:TextBox runat="server" ID="txtMaatschappijID" Text='<%# Bind("Maatschappij") %>' />
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                    <asp:Button ID="btnOpslaanID" CommandName="Update" Text="Opslaan" runat="server" CssClass="submitButton" />
                                </td>
                                <td> </td>
                            </tr>
                        </table>
     
                    </FormTemplate>
                </EditFormSettings>
            </MasterTableView>
            <SortingSettings SortedBackColor="Azure" EnableSkinSortStyles="false" SortToolTip="Klik hier om te sorteren" />
            <PagerStyle Mode="NextPrevAndNumeric" Position="Bottom" />
            <HeaderStyle Width="100px" />
        </telerik:RadGrid>
    </asp:Panel>


    .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;
     
    namespace SitefinityWebApp.Modules.ConsumentenClaim.BackEnd.Aanbieder
    {
        public partial class Edit : System.Web.UI.UserControl
        {
            //protected void Page_Load(object sender, EventArgs e)
            protected void trgMaatschappijID_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
            {
                if (Request.Params["maatschappijid"] != null)
                {
                    int maatschappijid = Convert.ToInt32(Request.Params["maatschappijid"]);
     
                    var producten = ccWebsite.Aanbieder.AanbiederProductBase.SelectAll().Where(x => x.Distributiestatus != 3 && x.MaatschappijId == maatschappijid);
                    //trgProductID.DataSource = producten;
                    //trgProductID.DataBind();
     
                    //pnlProductID.Visible = true;
                    pnlMaatschappijID.Visible = false;
                }
                else
                {
                    //var maatschappijen = ccWebsite.Aanbieder.Aanbieder_MaatschappijBase.SelectAll();
     
                    var product = from products in ccWebsite.Aanbieder.AanbiederProductBase.SelectAll()
                                  group products by products.MaatschappijId into g
                                  select new
                                  {
                                      MaatschappijId = g.Key,
                                      AantalProducten = g.Count()
                                  };
     
                    var result = from p in product
                                 join m in ccWebsite.Aanbieder.Aanbieder_MaatschappijBase.SelectAll()
                                 on p.MaatschappijId equals m.MaatschappijId
                                 select new
                                 {
                                     Maatschappij = m.Naam,
                                     AantalProducten = p.AantalProducten,
                                     MaatschappijId = m.MaatschappijId
                                 };
     
                    trgMaatschappijID.DataSource = result;
                    //trgMaatschappijID.DataBind();
     
                    //pnlProductID.Visible = false;
                    pnlMaatschappijID.Visible = true;
                }
                 
            }
     
            protected void trgMaatschappijID_Item(object source, GridUpdatedEventArgs e)
            {
                if (e.Exception == null)
                {
     
     
                    //if (e.CommandName == RadGrid.UpdateCommandName)
                    //{
                    if (e.Item is GridEditFormItem)
                    {
                        GridEditFormItem item = (GridEditFormItem)e.Item;
                        int maatschappijid = Convert.ToInt32(item.GetDataKeyValue("MaatschappijId"));
                        var maatschappij = ccWebsite.Aanbieder.Aanbieder_MaatschappijBase.SelectOne(new ccWebsite.Aanbieder.Aanbieder_MaatschappijPrimaryKey(maatschappijid));
                        //maatschappij.Naam = item.GetDataKeyValue("Maatschappij").ToString();
                        TextBox txtOpslaan = (TextBox)item.FindControl("txtOpslaanID");
                        maatschappij.Naam = txtOpslaan.Text;
                        maatschappij.Update();
                    }
                }
            }
        }
    }


    DESIGNER:
    //------------------------------------------------------------------------------
    // <auto-generated>
    //     This code was generated by a tool.
    //
    //     Changes to this file may cause incorrect behavior and will be lost if
    //     the code is regenerated.
    // </auto-generated>
    //------------------------------------------------------------------------------
     
    namespace SitefinityWebApp.Modules.ConsumentenClaim.BackEnd.Aanbieder {
         
         
        public partial class Edit {
             
            /// <summary>
            /// pnlMaatschappijID control.
            /// </summary>
            /// <remarks>
            /// Auto-generated field.
            /// To modify move field declaration from designer file to code-behind file.
            /// </remarks>
            protected global::System.Web.UI.WebControls.Panel pnlMaatschappijID;
             
            /// <summary>
            /// trgMaatschappijID control.
            /// </summary>
            /// <remarks>
            /// Auto-generated field.
            /// To modify move field declaration from designer file to code-behind file.
            /// </remarks>
            protected global::Telerik.Web.UI.RadGrid trgMaatschappijID;
        }
    }

  10. ConsumentenClaim
    ConsumentenClaim avatar
    14 posts
    Member since:
    Oct 2010

    Posted 12 Dec 2011 Link to this post

    Hi,

    Can anyone copy paste the code posted above in his/her own project and verify the code is working on your side.

    Regards
  11. ConsumentenClaim
    ConsumentenClaim avatar
    14 posts
    Member since:
    Oct 2010

    Posted 13 Dec 2011 Link to this post

    Hi,

    I must have seen more than a hundred threads. I have tried tons of solution but none of them worked so far.

    If anyone have a single idea how to fix it, I'd love to hear!
  12. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 14 Dec 2011 Link to this post

    Hello,


    I would  suggest you to review the following online resources which elaborates on FormTemplate editing:

    http://www.telerik.com/help/aspnet-ajax/grid-updating-values-usercontrol-formtemplate.html
    http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/templateformupdate/defaultvb.aspx


    All the best,
    Maria Ilieva
    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
  13. ConsumentenClaim
    ConsumentenClaim avatar
    14 posts
    Member since:
    Oct 2010

    Posted 14 Dec 2011 Link to this post

    Hi Maria,

    Thank you for your reponse.

    I have seen the two links you provided before. The answer is unfortunally not there.
    Regards
  14. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 16 Dec 2011 Link to this post

    Hello,

    At this point it will best if you could open a regular support ticket and send us sample runnable application which demonstrates the described problem as well as the exact steps for replicating the issue. Thus we will be able to debug the application locally and advise you further.

    Greetings,
    Maria Ilieva
    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017