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

Terelik PostBack Lost All data and do any action.

3 Answers 144 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jorge
Top achievements
Rank 1
Jorge asked on 22 Nov 2013, 08:44 PM

Hi guys!

I have the following scenario .
[
I use RadControls for ASP.NET AJAX Q1 2012
Visual Studio 2010
C# & Asp
 
]

1 Aspx
5 User Controls
    UserControlCatalogo
    UserControlDetalle
    UserControlDetalleInterno1
    UserControlDetalleInterno2
    UserControlDetalleInterno3

The aspx page contains a call to " UserControlCatalogo " contains a RadGrid with this data, choose "edit " or "new " in this open RadGrid PopUp containing at UserControlDetalle .

The UserControlDetalle contains a set of RadTextBox and RadTabStrip ( tab panel ) which contains three tabs .

Tab 1 -> contains UserControlDetalleInterno1
Tab 2 -> contains UserControlDetalleInterno2
Tab 3 -> contains UserControlDetalleInterno3

UserControlDetalleInterno1 contains another RadGrid you want to do the following : By clicking on "new" or "edit " expands to display fields and add new data.

The problem is that when I use the "edit" or "new" function from radgrid, the template is not opened to fill data only "flashes" the popup and the table does nothing * in debuging enters the post back , refresh bd updates, the radgrid  datasourse * ... and ends ... * if I remove "ObtenerDatos", the table does not appear *

i cant add or edit my radgrid items :C

UserControlDetalleInterno1 ASPCode (yes, other name)
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="OrdenServicioCU.ascx.cs"
    Inherits="Presentation.Web.Catalogos.Cat_Contratos.OrdenServicioCU" %>
<telerik:RadGrid ID="rgOrdenServicio" runat="server" AllowMultiRowEdit="true" Visible="true"
    AllowPaging="True" GridLines="None" AllowAutomaticUpdates="true" AutoGenerateColumns="false"
    AllowAutomaticInserts="true" AllowAutomaticDeletes="true" AllowSorting="true">
    <MasterTableView CommandItemDisplay="Top" DataKeyNames="ID" NoMasterRecordsText="No hay datos a mostrar.">
        <PagerStyle Mode="NumericPages"></PagerStyle>
        <Columns>
            <telerik:GridEditCommandColumn ButtonType="ImageButton">
            </telerik:GridEditCommandColumn>
            <telerik:GridBoundColumn DataField="ID" HeaderText="ID" Visible="false">
                <HeaderStyle Width="1px" />
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="OrdenServicio" HeaderText="Orden de Servicio"
                ReadOnly="True">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="FechaInicio" DataType="System.DateTime" HeaderText="Fecha de Inicio"
                SortExpression="FechaInicio" UniqueName="FechaInicio" DataFormatString="{0:D}">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="FechaTermino" DataType="System.DateTime" HeaderText="Fecha de Termino"
                SortExpression="FechaTermino" UniqueName="FechaTermino" DataFormatString="{0:D}">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="MontoAsignado" DataType="System.Decimal" HeaderText="Monto Asignado"
                SortExpression="MontoAsignado" UniqueName="MONTO_ASIGNADO">
            </telerik:GridBoundColumn>
            <telerik:GridButtonColumn CommandName="Delete" ButtonType="ImageButton">
            </telerik:GridButtonColumn>
        </Columns>
        <EditFormSettings EditFormType="Template">
            <EditColumn UniqueName="EditCommandColumn1">
            </EditColumn>
            <FormTemplate>
                <table cellspacing="2" cellpadding="1" width="100%" border="0">
                    <tr style="visibility: hidden">
                        <td colspan="2">
                            <b>ID:
                                <%# Eval("ID")%>
                            </b>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Orden de Servicio:
                        </td>
                        <td>
                            <asp:TextBox Width="200px" ID="TextBox1" runat="server" Text='<%# Bind("OrdenServicio") %>'></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Fecha de Inicio:
                        </td>
                        <td>
                            <asp:TextBox Width="200px" ID="TextBox2" runat="server" Text='<%# DataBinder.Eval( Container, "DataItem.FechaInicio" )%>'></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Fecha de Termino:
                        </td>
                        <td>
                            <asp:TextBox Width="200px" ID="TextBox3" runat="server" Text='<%# DataBinder.Eval( Container, "DataItem.FechaTermino" )%>'></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Monto Asignado:
                        </td>
                        <td>
                            <asp:TextBox Width="200px" ID="TextBox4" runat="server" Text='<%# DataBinder.Eval( Container, "DataItem.MontoAsignado" )%>'></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <asp:Button ID="Button1" runat="server" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                                CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'
                                OnClick="btnInsertOrden_clic"></asp:Button>
                            <asp:Button ID="Button2" runat="server" Text="Cancel" CausesValidation="false" CommandName="Cancel">
                            </asp:Button>
                        </td>
                    </tr>
                </table>
            </FormTemplate>
        </EditFormSettings>
    </MasterTableView>
</telerik:RadGrid>

UserControlDetalleInterno1.cs CodeBehind (yes, other name)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ServicesReferencesCore.CatalogoService;
using Telerik.Web.UI;
 
namespace Presentation.Web.Catalogos.Cat_Contratos
{
    public partial class OrdenServicioCU : System.Web.UI.UserControl
    {
        CatalogoServiceClient CatClient = new CatalogoServiceClient();
        public ContratoDTO Contrato = new ContratoDTO();
        List<OrdenServicioDTO> lstOrdenServicio;
 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Contrato.Id > 0)
            {
                ObtenerDatos();
                Session["contrato"] = Contrato;
            }
            else
            {
                if (Session["contrato"] != null)
                    Contrato = Session["contrato"] as ContratoDTO;
            }
        }
 
        private void ObtenerDatos()
        {
            if (Contrato != null)
            {
                if (Contrato.Id > 0)
                {
                    CatClient = new CatalogoServiceClient();
 
                    lstOrdenServicio = new List<OrdenServicioDTO>();
                    lstOrdenServicio = CatClient.ObtenerOrdenServicioContrato(Contrato.Id);
 
                    rgOrdenServicio.DataSource = lstOrdenServicio;
                    rgOrdenServicio.DataBind();
                }
                else
                {
                    lstOrdenServicio = new List<OrdenServicioDTO>();
                    rgOrdenServicio.DataSource = lstOrdenServicio;
                    rgOrdenServicio.DataBind();
                }
            }
            else
            {
                lstOrdenServicio = new List<OrdenServicioDTO>();
                rgOrdenServicio.DataSource = lstOrdenServicio;
                rgOrdenServicio.DataBind();
            }
        }
 
        #region Eventos
        protected void btnInsertOrden_clic(object sender, EventArgs e)
        {
            //codigo para guardar los datos en la bd
        }
        #endregion
    }
}

Thanks All!

PD: im bad on english, but i try it n.nU

3 Answers, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 27 Nov 2013, 09:18 AM
Hi Jorge,

I noticed that you have use a simple data binding in your grid with the automatic CRUD operation which is not supported scenario. In order to use an automatic Insert/Update/Delete operation you have to use the advanced data binding. The aforementioned data binding topics elaborate more on the difference between the two methods and how to implement them into your project.

Regards,
Kostadin
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
Jorge
Top achievements
Rank 1
answered on 27 Nov 2013, 03:40 PM

Hi! thanks for help!.

i use OnNeedDataSource in my rad grid, but i cant open my item template for add/edit item button, do not do anything.

I want to do something like this [picture attach] for Edit or Add ... but my popup only do a flash but no open my template
.
my new header grid 

<telerik:RadGrid ID="rgOrdenServicio" runat="server" AllowMultiRowEdit="true" Visible="true"
    AllowPaging="True" GridLines="None" AllowAutomaticUpdates="true" AutoGenerateColumns="false"
    AllowAutomaticInserts="true" AllowAutomaticDeletes="true" AllowSorting="true"
    OnNeedDataSource="rgOrdenServicio_NeedDataSource">

[ ... all code in the last post ]

my new code behind

public partial class OrdenServicioCU : System.Web.UI.UserControl
    {
        CatalogoServiceClient CatClient = new CatalogoServiceClient();
        public ContratoDTO Contrato = new ContratoDTO();
        List<OrdenServicioDTO> lstOrdenServicio;
 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Contrato.Id > 0)
            {
                Session["contrato"] = Contrato;
            }
            else
            {
                if (Session["contrato"] != null)
                    Contrato = Session["contrato"] as ContratoDTO;
            }
        }
 
        private List<OrdenServicioDTO> ObtenerDatos()
        {
            lstOrdenServicio = new List<OrdenServicioDTO>();
 
            if (Contrato != null)
            {
                if (Contrato.Id > 0)
                {
                    CatClient = new CatalogoServiceClient();
 
                    //lstOrdenServicio = new List<OrdenServicioDTO>();
                    lstOrdenServicio = CatClient.ObtenerOrdenServicioContrato(Contrato.Id);
 
                    //rgOrdenServicio.DataSource = lstOrdenServicio;
                    //rgOrdenServicio.DataBind();
                }
            }
            return lstOrdenServicio;
        }
 
        #region Eventos
        protected void btnInsertOrden_clic(object sender, EventArgs e)
        {
            //codigo para guardar los datos en la bd
        }
 
        protected void rgOrdenServicio_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            rgOrdenServicio.DataSource = ObtenerDatos();
        }
        #endregion
    }

thank for helping me
0
Kostadin
Telerik team
answered on 02 Dec 2013, 01:18 PM
Hi Jorge,

As far as I can see your code looks correct. Could you please provide a small runnable sample in order to observe the issue further? Meanwhile I would recommend you to examine the following live demo which demonstrates how to implement an edit form template.

Regards,
Kostadin
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.
Tags
General Discussions
Asked by
Jorge
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Jorge
Top achievements
Rank 1
Share this question
or