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

Update events not firing

12 Answers 159 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ConsumentenClaim
Top achievements
Rank 1
ConsumentenClaim asked on 04 Dec 2011, 09:27 AM
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>

12 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 05 Dec 2011, 04:37 AM
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.
0
ConsumentenClaim
Top achievements
Rank 1
answered on 06 Dec 2011, 06:01 AM
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;
            }

0
Shinu
Top achievements
Rank 2
answered on 06 Dec 2011, 06:14 AM
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.
0
ConsumentenClaim
Top achievements
Rank 1
answered on 06 Dec 2011, 09:49 AM
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.
0
Maria Ilieva
Telerik team
answered on 08 Dec 2011, 03:42 PM
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
0
Pablo
Top achievements
Rank 1
answered on 08 Dec 2011, 11:54 PM
Check this example: http://beecy.net/post/2009/01/07/telerik-radgrid-formtemplate-codebehind.aspx. It seems that is what you want to accomplish
0
ConsumentenClaim
Top achievements
Rank 1
answered on 09 Dec 2011, 11:23 AM
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;
    }
}

0
ConsumentenClaim
Top achievements
Rank 1
answered on 12 Dec 2011, 09:49 PM
Hi,

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

Regards
0
ConsumentenClaim
Top achievements
Rank 1
answered on 13 Dec 2011, 04:36 PM
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!
0
Maria Ilieva
Telerik team
answered on 14 Dec 2011, 09:07 AM
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
0
ConsumentenClaim
Top achievements
Rank 1
answered on 14 Dec 2011, 09:48 AM
Hi Maria,

Thank you for your reponse.

I have seen the two links you provided before. The answer is unfortunally not there.
Regards
0
Maria Ilieva
Telerik team
answered on 16 Dec 2011, 03:02 PM
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
Tags
Grid
Asked by
ConsumentenClaim
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
ConsumentenClaim
Top achievements
Rank 1
Maria Ilieva
Telerik team
Pablo
Top achievements
Rank 1
Share this question
or