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

Need an event when Radgrid ends all the Inserts/Updates

5 Answers 102 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Julio
Top achievements
Rank 1
Julio asked on 08 Aug 2013, 08:17 PM
Hi Im trying to implement this demo. Does anybody knows an event or how to implement an event to fire when I click the "Save Changes" and the RadGrid ends all the Inserts/Updates? Is there any property that says how many pending changes are left or something? I need to do this to execute a final process in the database. Thanks.

Here is my code for the radgrid
<telerik:RadGrid ID="RG_CorreosExtra" runat="server" AutoGenerateColumns="False" AllowSorting="true" AllowPaging="True" PageSize="25" OnBatchEditCommand="RG_CorreosExtra_BatchEditCommand" OnInsertCommand="RG_CorreosExtra_InsertCommand" OnUpdateCommand="RG_CorreosExtra_UpdateCommand" OnDeleteCommand="RG_CorreosExtra_DeleteCommand" OnNeedDataSource="RG_CorreosExtra_NeedDataSource" Skin="Web20">
<MasterTableView CommandItemDisplay="Top" DataKeyNames="id" HorizontalAlign="NotSet" EditMode="Batch" Name="Detalle_Correos_Extra">
<NoRecordsTemplate>
No hay correos en la lista
</NoRecordsTemplate>
<CommandItemSettings AddNewRecordText="Nuevo Correo" SaveChangesText="Guardar Cambios"CancelChangesText="Cancelar" RefreshText="Actualizar" />
        <BatchEditingSettings EditType="Cell" OpenEditingEvent="Click" />
        <Columns>
            <telerik:GridTemplateColumn DataField="correo" HeaderText="Correo" UniqueName="correo"
                SortExpression="correo">
                <ItemStyle HorizontalAlign="Left" />
                <ItemTemplate>
                    <%# Eval("correo") %>
                </ItemTemplate>
                <EditItemTemplate>
                    <telerik:RadTextBox ID="RT_correo" runat="server" Text='<%# Bind("correo") %>'>
                    </telerik:RadTextBox>
                    <asp:RequiredFieldValidator ID="RFV_correo" runat="server" ControlToValidate="RT_correo"
                        ForeColor="Red" ErrorMessage="Debe ingresar correo electrónico." Text="*" Display="Dynamic">
                    </asp:RequiredFieldValidator>
                    <asp:RegularExpressionValidator ID="FEV_correo" runat="server" ControlToValidate="RT_correo"
                        ForeColor="Red" ErrorMessage="Formato de correo inválido." Text="Formato Inválido"
                        Display="Dynamic" Font-Size="X-Small" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">
                    </asp:RegularExpressionValidator>
                </EditItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn DataField="nombre" HeaderText="Nombre" UniqueName="nombre"
                SortExpression="nombre">
                <ItemStyle HorizontalAlign="Left" />
                <ItemTemplate>
                    <%# Eval("nombre") %>
                </ItemTemplate>
                <EditItemTemplate>
                    <telerik:RadTextBox ID="RT_nombre" runat="server" Text='<%# Bind("nombre") %>'>
                    </telerik:RadTextBox>
                    <asp:RequiredFieldValidator ID="RFV_nombre" runat="server" ControlToValidate="RT_nombre"
                        ForeColor="Red" ErrorMessage="Debe ingresar Nombre." Text="*" Display="Dynamic">
                    </asp:RequiredFieldValidator>
                </EditItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn DataField="descripcion" HeaderText="Descripción" UniqueName="descripcion">
                <ItemStyle HorizontalAlign="Left" />
                <ItemTemplate>
                    <%# Eval("descripcion") %>
                </ItemTemplate>
                <EditItemTemplate>
                    <telerik:RadTextBox ID="RT_descripcion" runat="server" Text='<%# Bind("descripcion") %>'>
                    </telerik:RadTextBox>
                </EditItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridButtonColumn ConfirmText="¿Desea eliminar este correo?" ConfirmDialogType="RadWindow"
                ConfirmTitle="Eliminación de correo" HeaderText="Eliminar" ButtonType="ImageButton"
                CommandName="Delete" Text="Eliminar" UniqueName="DeleteColumn">
                <HeaderStyle Width="60px" />
                <ItemStyle HorizontalAlign="Center" />
            </telerik:GridButtonColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

One last thing, how can I do to make the RequiredFieldValidator for the RadTextBox "RT_nombre" activates only for new records when I clic "Save Changes" if I am not editing the cell.

5 Answers, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 09 Aug 2013, 10:37 AM
Hello,

Please try with the below code snippet.

<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource"
       DataSourceID="SqlDataSource1" AutoGenerateColumns="False" AllowAutomaticUpdates="True"
       AllowAutomaticInserts="true" AllowAutomaticDeletes="true" OnPreRender="RadGrid1_PreRender"
       OnBatchEditCommand="RadGrid1_BatchEditCommand">
       <MasterTableView EditMode="Batch" DataSourceID="SqlDataSource1" CommandItemDisplay="Top">
           <Columns>
               <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
               </telerik:GridBoundColumn>
               <telerik:GridBoundColumn DataField="Name" HeaderStyle-Width="210px" HeaderText="Name"
                   SortExpression="Name" UniqueName="Name">
                   <ColumnValidationSettings EnableRequiredFieldValidation="true">
                       <RequiredFieldValidator ForeColor="Red" Text="*This field is required">
                       </RequiredFieldValidator>
                   </ColumnValidationSettings>
               </telerik:GridBoundColumn>
           </Columns>
       </MasterTableView>
   </telerik:RadGrid>
   <asp:Label ID="Label1" runat="server"></asp:Label>
   <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:JayeshTestConnectionString %>"
       DeleteCommand="DELETE FROM [TableTest] WHERE [ID] = @ID" InsertCommand="INSERT INTO [TableTest] ([Name], [ID]) VALUES (@Name, @ID)"
       SelectCommand="SELECT [Name], [ID] FROM [TableTest]" UpdateCommand="UPDATE [TableTest] SET [Name] = @Name WHERE [ID] = @ID">
       <DeleteParameters>
           <asp:Parameter Name="ID" Type="Int32" />
       </DeleteParameters>
       <InsertParameters>
           <asp:Parameter Name="Name" Type="String" />
           <asp:Parameter Name="ID" Type="Int32" />
       </InsertParameters>
       <UpdateParameters>
           <asp:Parameter Name="Name" Type="String" />
           <asp:Parameter Name="ID" Type="Int32" />
       </UpdateParameters>
   </asp:SqlDataSource>
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
   {
 
       dynamic data1 = new[] {
              new { ID = 1, Name ="Name_1"},
              new { ID = 2, Name = "Name_2"},
              new { ID = 3, Name = "Name_1"},
              new { ID = 4, Name = "Name_4"},
              new { ID = 5, Name = "Name_1"}
          };
 
       RadGrid1.DataSource = data1;
 
   }
   bool IsBacthUpdateIsFired = false;
   protected void RadGrid1_PreRender(object sender, EventArgs e)
   {
       if (IsBacthUpdateIsFired)
       {
           Label1.Text = "Your message comes here" + DateTime.Now.ToString();
           IsBacthUpdateIsFired = false;
       }
   }
   protected void RadGrid1_BatchEditCommand(object sender, GridBatchEditingEventArgs e)
   {
       IsBacthUpdateIsFired = true;
   }

Let me know if any concern.

Thanks,
Jayesh Goyani
0
Julio
Top achievements
Rank 1
answered on 09 Aug 2013, 04:04 PM
It works thanks!

Just one more question. In the demo how to make the RequireFieldValidator for UnitPrice to activate when I save changes wihout editing the cell. I explain it in the attached image.
0
Jayesh Goyani
Top achievements
Rank 2
answered on 12 Aug 2013, 09:53 AM
Hello Telerik Admin,

Can you please look into this issue?

I am able to reproduce this issue in two case.

Initial screen.



1. In insert mode

2. Edit mode (if product name is blank before edit the productname column)


Note : if i set one or more empty space in Textbox then it works.


Thanks,
Jayesh Goyani
0
Maria Ilieva
Telerik team
answered on 13 Aug 2013, 11:45 AM
Hello Jayesh,

Could you please share your RadGrid markup as well as the related code behind so that we could try to replicate the issue locally and further investigate its root cause?

Regards,
Maria Ilieva
Telerik
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 the blog feed now.
0
Jayesh Goyani
Top achievements
Rank 2
answered on 14 Aug 2013, 05:55 AM
Hello,

<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    </telerik:RadScriptManager>
    <telerik:RadWindowManager ID="RadWindowManager1" runat="server">
    </telerik:RadWindowManager>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                            <telerik:AjaxUpdatedControl ControlID="Label1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
    </telerik:RadAjaxLoadingPanel>
    <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="False"
        AllowAutomaticUpdates="True" AllowAutomaticInserts="true" AllowAutomaticDeletes="true"
        OnPreRender="RadGrid1_PreRender" OnBatchEditCommand="RadGrid1_BatchEditCommand">
        <MasterTableView EditMode="Batch" DataSourceID="SqlDataSource1" CommandItemDisplay="Top">
            <Columns>
                <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Name" HeaderStyle-Width="210px" HeaderText="Name"
                    SortExpression="Name" UniqueName="Name">
                    <ColumnValidationSettings EnableRequiredFieldValidation="true">
                        <RequiredFieldValidator ForeColor="Red" Text="*This field is required">
                        </RequiredFieldValidator>
                    </ColumnValidationSettings>
                </telerik:GridBoundColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>
    <asp:Label ID="Label1" runat="server"></asp:Label>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:JayeshTestConnectionString %>"
        DeleteCommand="DELETE FROM [TableTest] WHERE [ID] = @ID" InsertCommand="INSERT INTO [TableTest] ([Name], [ID]) VALUES (@Name, @ID)"
        SelectCommand="SELECT [Name], [ID] FROM [TableTest]" UpdateCommand="UPDATE [TableTest] SET [Name] = @Name WHERE [ID] = @ID">
        <DeleteParameters>
            <asp:Parameter Name="ID" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="Name" Type="String" />
            <asp:Parameter Name="ID" Type="Int32" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="Name" Type="String" />
            <asp:Parameter Name="ID" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>
    </form>
</body>
public partial class Forum : System.Web.UI.Page
{
 
 
    protected void Page_Init(object sender, System.EventArgs e)
    {
 
    }
    protected void Page_Load(object sender, System.EventArgs e)
    {
        
    }
    protected void Page_PreRender(object sender, System.EventArgs e)
    {
         
    }
 
 
 
 
    //protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    //{
 
    //    dynamic data1 = new[] {
    //          new { ID = 1, Name ="Name_1"},
    //          new { ID = 2, Name = "Name_2"},
    //          new { ID = 3, Name = "Name_1"},
    //          new { ID = 4, Name = "Name_4"},
    //          new { ID = 5, Name = "Name_1"}
    //      };
 
    //    RadGrid1.DataSource = data1;
 
    //}
    bool IsBacthUpdateIsFired = false;
    protected void RadGrid1_PreRender(object sender, EventArgs e)
    {
        if (IsBacthUpdateIsFired)
        {
            Label1.Text = "Your message comes here" + DateTime.Now.ToString();
            IsBacthUpdateIsFired = false;
        }
    }
    protected void RadGrid1_BatchEditCommand(object sender, GridBatchEditingEventArgs e)
    {
        IsBacthUpdateIsFired = true;
    }
 
}

<connectionStrings>
  <add name="JayeshTestConnectionString" connectionString="Data Source=PC222\SQL2008;Initial Catalog=JayeshTest;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>


SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TableTest](
    [ID] [int] NOT NULL,
    [Name] [nvarchar](50) NULL,
 CONSTRAINT [PK_TableTest] PRIMARY KEY CLUSTERED
(
    [ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
INSERT [dbo].[TableTest] ([ID], [Name]) VALUES (1, N'Jayesh')
INSERT [dbo].[TableTest] ([ID], [Name]) VALUES (2, N'goyani')
INSERT [dbo].[TableTest] ([ID], [Name]) VALUES (3, N'test')
INSERT [dbo].[TableTest] ([ID], [Name]) VALUES (5, NULL)


Steps to reproduce this this.

Issue 1 (Insert mode) :
-> Click on add new record
-> insert any number in ID
-> Now click on Name column in the same row
-> Do not insert anything in this textbox and click on save.
-> It is saved record
-> issue is Required field validator is not fired

Now again follow the below step.
-> Click on add new record
-> insert any number in ID
-> Now click on Name column in the same row
-> Insert one space " " in textbox  and click on save.
-> It is not saved record and fired required field validator
-> Working perfectly in this case

Issue 2 (Edit Mode) :
-> Edit the name field where ID is 5.
-> Do not insert anything in this textbox and click on save.
-> It is saved record
-> issue is Required field validator is not fired

Let me know if any concern.

Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Julio
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Julio
Top achievements
Rank 1
Maria Ilieva
Telerik team
Share this question
or