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

Two different insert edit forms in same grid

3 Answers 179 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Carola
Top achievements
Rank 1
Carola asked on 16 Dec 2012, 08:40 PM
Hi everyone,
Need some help here. 
I have two tables; orders and order_detail. Orders table has only 3 columns. The major information is in the detail.
I'm showing the whole information (order + detail) in the same row in a rad grid. I populate the grid with the OnNeedDataSource.
Grid EditMode is PopUp and I'm using an Edit Form Template.

Now, I have two different insert scenarios:
1 - The add new record (on top of the grid), inserts new order with default order detail. Press the button, popup opens, inserts and everything works fine.
2 - I need another insert button, to add a new item (detail) for an order. This would mean, open popup Edit Form Template, with order_id, customer and blocking information, and all of the attributes corresponding to the new item, should be blank.

Question is, how can I call the pop up Edit Form Template from the GridButton Button Column?
My asp structure is:
<telerik: radGrid....
     .....
     <Columns>
           <telerik:GridButtonColumn />
     </Columns>

     <EditFormSettings InsertCaption="Add Order" CaptionFormatString="EditOrder: {0}"
              CaptionDataField="PedidoDetalleId" EditFormType="Template" >
           <EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
           <PopUpSettings Width="60%" />
           <FormTemplate>
<table>
</>
           </FormTemplete>
    </EditFormSettings>
</telerik:radGrid>

Thank you so much in advance
Carol

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 17 Dec 2012, 05:15 AM
Hi,

Please try the following code snippet.

C#:
protected void RadGrid2_ItemCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == "Edit")
    {
        RadGrid2.MasterTableView.EditFormSettings.EditFormType = GridEditFormType.Template;
    }
}

Thanks,
Shinu.
0
Carola
Top achievements
Rank 1
answered on 19 Dec 2012, 12:54 AM
Shinu,
thanks for your reply.
Actually, what I need is to open the popup edit form template on clicking the button.
Inside the rad grid (in aspx) I created the form template
                <EditFormSettings InsertCaption="Agregar nuevo Pedido" CaptionFormatString="EditarPedido: {0}"
                    CaptionDataField="PedidoDetalleId" EditFormType="Template" ColumnNumber="6" >
                    <EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
                    <PopUpSettings Width="60%" />
                    <FormTemplate>
                        <table id="tblDatos" cellspacing="2" cellpadding="1" border="0" style="width: 100%">
                            <tr class="label">
                                <td colspan="3">
                                    <b>Datos de cabecera</b>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="6">
                                    <hr />
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Cliente:
                                </td>
                                <td colspan="2">
                                    <asp:DropDownList ID="ddlClienteEdit" runat="server" 
                                        SelectedValue='<%# (Container is GridEditFormInsertItem) ? "1" : Eval("ClienteId") %>'
                                        DataSourceID="dataClientes" DataTextField="cliente_nombre"
                                        Style="z-index: 1;" DataValueField="cliente_id" OnSelectedIndexChanged="ClienteChange">
                                    </asp:DropDownList>
                                </td>
                            </tr>

                            <tr>
                                <td>
                                    Fecha Venta:
                                </td>
                                <td>
                                    <telerik:RadDatePicker ID="txtFechaVenta" runat="server" Width="100px" Calendar-CultureInfo="es-AR" 
                                        Calendar-FirstDayOfWeek="Monday" DBSelectedDate='<%# Bind("PedidoFechaVenta") %>' >
                                    </telerik:RadDatePicker>
                                </td>
                                <td>
                                    Bloqueo Comercial:
                                </td>
                                <td>
                                    <asp:CheckBox ID="chkBloqueo" runat="server" Checked='<%# (Container is GridEditFormInsertItem) ? false : Eval("PedidoBloqueoComercial") %>' />
                                </td>
                            </tr>

                            <tr></tr>

                            <tr class="label">
                                <td colspan="3">
                                    <b>Datos del Item</b>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="6">
                                    <hr />
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Producto:
                                </td>
                                <td>
                                    <asp:DropDownList ID="ddlProductoEdit" runat="server" 
                                        SelectedValue='<%# (Container is GridEditFormInsertItem) ? "1" : Eval("ProductoId") %>'
                                        DataSourceID="dataProductos" DataTextField="producto_descripcion"
                                        Style="z-index: 1;" DataValueField="producto_id" OnSelectedIndexChanged="ProductoChange" AutoPostBack="true" >
                                    </asp:DropDownList>
                                </td>
                                <td>
                                    Fecha Promesa:
                                </td>
                                <td>
                                    <telerik:RadDatePicker ID="txtFechaPromesa" runat="server" Width="100px" Calendar-CultureInfo="es-AR" 
                                        Calendar-FirstDayOfWeek="Monday" DBSelectedDate='<%# Bind("PedidoFechaPromesa") %>' >
                                    </telerik:RadDatePicker>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Ancho
                                </td>
                                <td>
                                    <telerik:RadNumericTextBox ID="txtAncho" DbValue='<%# Bind( "PedidoAncho") %>' runat="server" 
                                    DataType="System.Decimal" NumberFormat-DecimalDigits="2" />
                                </td>
                                <td>
                                    Alto
                                </td>
                                <td>
                                    <telerik:RadNumericTextBox ID="txtAlto" DbValue='<%# Bind( "PedidoAlto") %>' runat="server" 
                                    DataType="System.Decimal" NumberFormat-DecimalDigits="2" />
                                </td>
                                <td>
                                    Largo
                                </td>
                                <td>
                                    <telerik:RadNumericTextBox ID="txtLargo" DbValue='<%# Bind( "PedidoLargo") %>' runat="server" 
                                    DataType="System.Decimal" NumberFormat-DecimalDigits="2" />
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Cantidad
                                </td>
                                <td>
                                    <telerik:RadNumericTextBox ID="txtCantidad" DbValue='<%# Bind( "PedidoCantidad") %>' runat="server" 
                                    DataType="System.Int32" NumberFormat-DecimalDigits="0" />
                                </td>
                                <td>
                                    Rollos
                                </td>
                                <td>
                                    <telerik:RadNumericTextBox ID="txtCantidadRollos" DbValue='<%# Bind( "PedidoCantidadRollos") %>' runat="server" 
                                    DataType="System.Int32" NumberFormat-DecimalDigits="0" />
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Bandas
                                </td>
                                <td>
                                    <telerik:RadNumericTextBox ID="txtBandas" DbValue='<%# Bind( "PedidoBandas") %>' runat="server" 
                                    DataType="System.Int32" NumberFormat-DecimalDigits="0" />
                                </td>
                                <td>
                                    Cono
                                </td>
                                <td>
                                    <telerik:RadNumericTextBox ID="txtCono" DbValue='<%# Bind( "PedidoCono") %>' runat="server" 
                                    DataType="System.Decimal" NumberFormat-DecimalDigits="2" />
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Papel:
                                </td>
                                <td>
                                    <asp:DropDownList ID="ddlPapelEdit" runat="server" 
                                        SelectedValue='<%# (Container is GridEditFormInsertItem) ? "-1" : Eval("PapelId") %>'
                                        DataSourceID="dataPapeles" DataTextField="papel_nombre"
                                        Style="z-index: 1;" DataValueField="papel_id" AppendDataBoundItems="true">
                                        <asp:ListItem Value="-1">
                                          --Elija un Papel
                                        </asp:ListItem>  
                                    </asp:DropDownList>
                                </td>
                                <td>
                                    Ribbon:
                                </td>
                                <td>
                                    <asp:DropDownList ID="ddlTiposRibbonsEdit" runat="server" 
                                        SelectedValue='<%# (Container is GridEditFormInsertItem) ? "-1" : Eval("TipoRibbonId") %>'
                                        DataSourceID="dataTiposRibbons" DataTextField="tipo_ribbon_descripcion"
                                        Style="z-index: 1;" DataValueField="tipo_ribbon_id" AppendDataBoundItems="true" >
                                        <asp:ListItem Value="-1">
                                          --Elija un Ribbon
                                        </asp:ListItem>  
                                    </asp:DropDownList>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    A color:
                                </td>
                                <td>
                                    <asp:CheckBox ID="chkColor" runat="server" Checked='<%# (Container is GridEditFormInsertItem) ? false : Eval("PedidoColorCheck") %>'/>
                                </td>
                                <td>
                                    Color:
                                </td>
                                <td colspan="3">
                                    <asp:TextBox ID="txtColor" Text='<%# Bind( "PedidoColor") %>' runat="server" />
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Impresion:
                                </td>
                                <td>
                                    <asp:CheckBox ID="chkImpresion" runat="server" Checked='<%# (Container is GridEditFormInsertItem) ? false : Eval("PedidoImpresion") %>' />
                                </td>
                                <td>
                                    Caja Etifix:
                                </td>
                                <td>
                                    <asp:CheckBox ID="chkCajaEtifix" runat="server" Checked='<%# (Container is GridEditFormInsertItem) ? false : Eval("PedidoCajaEtifix") %>' />
                                </td>
                                <td>
                                    Retira:
                                </td>
                                <td>
                                    <asp:CheckBox ID="chkRetira" runat="server" Checked='<%# (Container is GridEditFormInsertItem) ? false : Eval("PedidoRetira") %>' />
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Precio Rollo
                                </td>
                                <td>
                                    <telerik:RadNumericTextBox ID="txtPrecioRollo" DbValue='<%# Bind( "PedidoPrecioRollo") %>' runat="server" 
                                    DataType="System.Decimal" NumberFormat-DecimalDigits="2" />
                                </td>
                                <td>
                                    Descuento (%)
                                </td>
                                <td>
                                    <telerik:RadNumericTextBox ID="txtDescuento" DbValue='<%# Bind( "PedidoDescuento") %>' runat="server" 
                                    DataType="System.Int16" NumberFormat-DecimalDigits="0" />
                                </td>
                                <td>
                                    Moneda:
                                </td>
                                <td>
                                    <asp:DropDownList ID="ddlMonedasEdit" runat="server" 
                                        SelectedValue='<%# (Container is GridEditFormInsertItem) ? "1" : Eval("MonedaId") %>'
                                        DataSourceID="dataMonedas" DataTextField="moneda_descripcion"
                                        Style="z-index: 1;" DataValueField="moneda_id" >
                                    </asp:DropDownList>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Observaciones:
                                </td>
                                <td colspan="4">
                                    <asp:TextBox ID="txtObservaciones" Text='<%# Bind( "PedidoObservaciones") %>' runat="server" width="200px"/>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Domicilio:
                                </td>
                                <td>
                                    <asp:DropDownList ID="ddlClienteDomicilioEdit" runat="server"  
                                        DataTextField="ClienteDomicilioDescripcion" DataValueField="ClienteDomicilioId" Style="z-index: 1">
  <%--                                      SelectedValue='<%# (Container is GridEditFormInsertItem) ? "-1" : Eval("ClienteDomicilioId") %>' >--%>
                                    </asp:DropDownList>
                                </td>
                            </tr>
                        </table>

                        <table style="width: 100%">
                            <tr>
                                <td align="right" colspan="2">
                                    <asp:Button ID="btnGrabar" Text='<%# (Container is GridEditFormInsertItem) ? "Agregar" : "Actualizar" %>'
                                        runat="server" 
                                        CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'> 
                                    </asp:Button>&nbsp;
                                    <asp:Button ID="btnCancelar" Text="Cancelar" runat="server" CausesValidation="False"  
                                        CommandName="Cancel">
                                    </asp:Button>
                                </td>
                            </tr>
                        </table>
                    </FormTemplate>
                </EditFormSettings>

Inside the Columns in the grid, I have muy button:

                    <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="AddItem" Text="Agregar Item al Pedido"
                        UniqueName="AddItem" HeaderStyle-Width="40px" ImageUrl="../Images/AddRecord.gif">
                        <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton"  ></ItemStyle>
                    </telerik:GridButtonColumn>

Now what I need to do when I click the button (of GridButtonColumn) is to open the Popup form edit template, changing some settings.
        protected void RgPedidosItemCommand(object sender, GridCommandEventArgs e)
        {
            if (e.CommandName == "AddItem")
            {
                //code to open the template 
            }
        }

Now, I'm new to telerik, so may be you come up saying this is not the best approach. So, your suggestion will be extremely useful!!

Thanks again.
Carol
0
Shinu
Top achievements
Rank 2
answered on 19 Dec 2012, 09:17 AM
Hi,

Try modifying your code as shown below.
aspx:
<telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Edit" ImageUrl="Images/edit.png"></telerik:GridButtonColumn>
C#:
protected void RadGrid2_ItemCommand(object sender, GridCommandEventArgs e)
 {
   if (e.CommandName == "Edit")
    {
        RadGrid2.MasterTableView.EditFormSettings.EditFormType = GridEditFormType.Template;
    }
}

Thanks,
Shinu.
Tags
General Discussions
Asked by
Carola
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Carola
Top achievements
Rank 1
Share this question
or