formview - insert item template - how to fill various textfields according to dropdown list selection?

hello All
I'm a beginner
I have the following scenario.  I have a web form for handling invoices which has a form view. When i'm in insert item template, I need to have various fields.  Some of them are contract number, invoice number, register date and other that are easy to handle. But there is a dropdown list related with a table of prices (the table has price name, price initial payment, number of payments, amount of month fee and soon).  So, when the dropdown is selected, fields related with price should get the values from price table, and then the user decides to keep them or type in new values.  How can I get it done?   Should I use a Dynamic populate extender or type all the code behind using SelectedIndexChanged method to populate price related controls?  what's the best approach?  This one is part of my degree project and it's driving me nuts?

Kindly advice

edo

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="frm_factura.aspx.cs" Inherits="Facturacion.Facturacion.frm_factura"   %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Página sin título</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
                            </asp:ScriptManager>
    <div>
        <asp:FormView ID="FormView1" runat="server" DataSourceID="odsFactura" 
            AllowPaging="True">
            <InsertItemTemplate>
                <table style="width:100%;">
                    <tr>
                        <td>
                            <asp:Label ID="lblNewFactura" runat="server" Text="Factura"></asp:Label>
                        </td>
                        <td>
                            <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("factnume") %>'></asp:TextBox>
                        </td>
                        <td>
                            <asp:Label ID="lblNewContrato" runat="server" Text="Contrato"></asp:Label>
                        </td>
                        <td>
                            <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("contnume") %>'></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:Label ID="lblNewFechaRegistro" runat="server" Text="Fecha de Registro"></asp:Label>
                        </td>
                        <td>
                            
                        </td>
                        <td>
                            <asp:Label ID="lblNewFechaLegalizacion" runat="server" 
                                Text="Fecha de Legalizacion"></asp:Label>
                        </td>
                        <td>
                            <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
                            <ajaxToolkit:CalendarExtender ID="TextBox4_CalendarExtender" runat="server" 
                                Enabled="True" TargetControlID="TextBox4">
                            </ajaxToolkit:CalendarExtender>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:Label ID="lblNewPlan" runat="server" Text="Plan"></asp:Label>
                        </td>
                        <td>
                           <asp:DropDownList ID="ddlplanes" runat="server" DataSourceID="ods_plan" DataTextField="plannomb" DataValueField="plannume">
            </asp:DropDownList>
                            <asp:ObjectDataSource ID="ods_plan" runat="server" 
                                OldValuesParameterFormatString="original_{0}" SelectMethod="GetAllPlanes" 
                                TypeName="Facturacion.DataSets.dsPlanTableAdapters.plannTableAdapter">
                            </asp:ObjectDataSource>
                        </td>
                        <td>
                            <asp:Label ID="lblNewPrecio" runat="server" Text="Precio"></asp:Label>
                        </td>
                        <td>
                            <asp:DropDownList ID="ddlprecios" runat="server" AutoPostBack="True" 
                                >
            </asp:DropDownList><br /><br />
        <%--ASP.NET AJAX CascadingDropDown--%>
        <ajaxToolkit:CascadingDropDown ID="CascadingDropDown1" runat="server" Category="Planes" 
                                LoadingText="Espere un momento.." ParentControlID="ddlplanes"
         PromptText="Seleccione un Precio" TargetControlID="ddlprecios" ServicePath="../PrecioService.asmx" 
                                ServiceMethod="GetPreciosByPlan" /></td>
                    </tr>
                    <tr>
                        <td>
                            <asp:Label ID="lblNewMaterial" runat="server" Text="Material"></asp:Label>
                        </td>
                        <td>
                            <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
                        </td>
                        <td>
                            &nbsp;</td>
                        <td>
                            &nbsp;</td>
                    </tr>
                    <tr>
                        <td>
                            <asp:Label ID="lblNewBasico" runat="server" Text="Basico"></asp:Label>
                        </td>
                        <td>
                            <asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("precbasi") %>'></asp:TextBox>
                        </td>
                        <td>
                            <asp:Label ID="lblNewRecargo" runat="server" Text="Recargo"></asp:Label>
                        </td>
                        <td>
                            <asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind("precreca") %>'></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:Label ID="lblNewInicial" runat="server" Text="Inicial"></asp:Label>
                        </td>
                        <td>
                            <asp:TextBox ID="TextBox8" runat="server" Text='<%# Bind("precinic") %>'></asp:TextBox>
                        </td>
                        <td>
                            <asp:Label ID="lblNewSaldo" runat="server" Text="Saldo"></asp:Label>
                        </td>
                        <td>
                            &nbsp;</td>
                    </tr>
                    <tr>
                        <td>
                            <asp:Label ID="lblNewCuotas" runat="server" Text="No Cuotas"></asp:Label>
                        </td>
                        <td>
                            <asp:TextBox ID="TextBox9" runat="server"></asp:TextBox>
                        </td>
                        <td>
                            <asp:Label ID="lblNewMensualidad" runat="server" Text="Mensualidad"></asp:Label>
                        </td>
                        <td>
                            <asp:TextBox ID="TextBox10" runat="server"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:Label ID="lblNewDiasCobranza" runat="server" Text="Dias de Cobranza"></asp:Label>
                        </td>
                        <td>
                            <asp:TextBox ID="TextBox11" runat="server"></asp:TextBox>
                        </td>
                        <td>
                            <asp:Label ID="lblNewVerificador" runat="server" Text="Verificador"></asp:Label>
                        </td>
                        <td>
                           <asp:DropDownList ID="ddlVerificador" runat="server" DataSourceID="OdsVerificador"
                            DataTextField="nomVerificador" DataValueField="verinume" SelectedIndex='<%# Bind("verinume") %>'
                            SelectedValue='<%# Bind("verinume") %>' Font-Size="Small">
                        </asp:DropDownList>
                        <asp:ObjectDataSource ID="odsVerificador" runat="server" SelectMethod="GetVerificadores"
                            TypeName="Facturacion.DAL.VerificadorDataLayer" ></asp:ObjectDataSource></td>
                    </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:Label ID="lblNewConsignado" runat="server" Text="Consignado"></asp:Label>
                        </td>
                        <td>
                            <asp:TextBox ID="TextBox12" runat="server"></asp:TextBox>
                        </td>
                        <td>
                            <asp:Label ID="lblNewRetenido" runat="server" Text="Retenido"></asp:Label>
                        </td>
                        <td>
                            <asp:TextBox ID="TextBox13" runat="server"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:Label ID="lblNewAnulado" runat="server" Text="Anulado"></asp:Label>
                        </td>
                        <td>
                            <asp:RadioButtonList ID="RadioButtonList2" runat="server" 
                            RepeatDirection="Horizontal" SelectedValue='<%# Bind("factanul") %>'>
                            <asp:ListItem Value="1">Si</asp:ListItem>
                            <asp:ListItem Value="0">No</asp:ListItem>
                        </asp:RadioButtonList></td>
                        <td>
                            &nbsp;</td>
                        <td>
                            &nbsp;</td>
                    </tr>
                    <tr>
                        <td colspan="4" style="text-align: right">
                            <asp:ObjectDataSource ID="odsPreciosFactura" runat="server"  
                                SelectMethod="GetPrecios" TypeName="Facturacion.DAL.PrecioDataLayer" 
                                OldValuesParameterFormatString="original_{0}">
                            </asp:ObjectDataSource>
                            <asp:LinkButton ID="lnkBtnInsertar" runat="server">Insertar</asp:LinkButton>
                            &nbsp;<asp:LinkButton ID="lnkCancelar" runat="server">Cancelar</asp:LinkButton>
                        </td>
                    </tr>
                </table>
           
            </InsertItemTemplate>
            <EmptyDataTemplate>
                No hay datos que mostrar<br />
                <asp:LinkButton ID="lnkNew" runat="server" CommandName="New">Nuevo</asp:LinkButton>
            </EmptyDataTemplate>
            
        </asp:FormView>
    
          
    
          
            <asp:ObjectDataSource ID="odsFactura" runat="server" InsertMethod="Insert" SelectMethod="GetFacturasPaged" 
        TypeName="Facturacion.DAL.FacturaDataLayer" 
        OldValuesParameterFormatString="original_{0}" EnablePaging="True"   >
           
                <SelectParameters>
                    <asp:Parameter Name="startRowIndex" Type="Int32" />
                    <asp:Parameter Name="maximumRows" Type="Int32" />
                    <asp:QueryStringParameter Name="Numero" QueryStringField="numero" 
                        Type="Int32" />
                </SelectParameters>
            <InsertParameters>
                <asp:Parameter Name="factnume" Type="Int32" />
                <asp:Parameter Name="contnume" Type="Int32" />
                <asp:Parameter Name="factfele" Type="DateTime" />
                <asp:Parameter Name="precnume" Type="Int32" />
                <asp:Parameter Name="matenume" Type="Int32" />
                <asp:Parameter Name="factbasi" Type="String" />
                <asp:Parameter Name="factreca" Type="String" />
                <asp:Parameter Name="factinic" Type="String" />
                <asp:Parameter Name="factsald" Type="String" />
                <asp:Parameter Name="factnucu" Type="String" />
                <asp:Parameter Name="factmens" Type="String" />
                <asp:Parameter Name="factdico" Type="DateTime" />
                <asp:Parameter Name="verinume" Type="Int32" />
                <asp:Parameter Name="factcons" Type="String" />
                <asp:Parameter Name="factrete" Type="String" />
                <asp:Parameter Name="factanul" Type="Byte" />
                <asp:Parameter Name="factdele" Type="Byte" />
            </InsertParameters>
        </asp:ObjectDataSource>
    
    </div>
    </form>
</body>
</html>

Open in new window

edocolAsked:
Who is Participating?
 
edocolConnect With a Mentor Author Commented:
I found the solution myself

protected void ddlprecios_SelectedIndexChanged(object sender, EventArgs e)
        {

            ObjectDataSource OdsPrecio = new ObjectDataSource();

            
            TextBox txtBasico = (TextBox)FormView1.Row.FindControl("txtNewBasico");
            TextBox txtRecargo = (TextBox)FormView1.Row.FindControl("txtNewRecargo");
            TextBox txtTotal = (TextBox)FormView1.Row.FindControl("txtNewTotal");
            TextBox txtInicial = (TextBox)FormView1.Row.FindControl("txtNewInicial");
            TextBox txtSaldo = (TextBox)FormView1.Row.FindControl("txtNewSaldo");
            TextBox txtCuotas = (TextBox)FormView1.Row.FindControl("txtNewCuotas");
            TextBox txtConsignado = (TextBox)FormView1.Row.FindControl("txtNewConsignado");
            TextBox txtRetenido = (TextBox)FormView1.Row.FindControl("txtNewRetenido");


            
            DropDownList ddlPrec = (DropDownList)FormView1.Row.FindControl("ddlprecios");
            DataTable dtsPrecios = new DataTable();
            dtsPrecios = DAL.PrecioDataLayer.GetPrecio(int.Parse(ddlPrec.SelectedValue));

    //0 [precnume] [smallint] IDENTITY(1,1) NOT NULL,
    //1 [plannume] [smallint] NOT NULL,
    //2 [precnomb] [varchar](4) COLLATE Modern_Spanish_CI_AS NOT NULL,
    //3 [precbasi] [money] NOT NULL,
    //4 [precreca] [money] NOT NULL,
    //5 [prectota] [money] NULL,
    //6 [precinic] [money] NULL,
    //7 [precsald] [money] NULL,
    //8 [preccuot] [money] NULL,
    //9 [preccons] [money] NULL,
    //10 [precrete] [money] NULL,
    //11 [preccomi] [money] NULL,
    //12 [precfecr] [datetime] NULL,
    //13 [precacti] [bit] NULL,


            if (dtsPrecios.Rows.Count > 0) // Check if the DataTable returns any data from database
            {

                txtBasico.Text = dtsPrecios.Rows[0]["precbasi"].ToString();
                txtRecargo.Text = dtsPrecios.Rows[0]["precreca"].ToString();
                txtTotal.Text = dtsPrecios.Rows[0]["prectota"].ToString();
                txtInicial.Text = dtsPrecios.Rows[0]["precinic"].ToString();
                txtSaldo.Text = dtsPrecios.Rows[0]["precsald"].ToString();
                txtCuotas.Text = dtsPrecios.Rows[0]["preccuot"].ToString();
                txtConsignado.Text = dtsPrecios.Rows[0]["preccons"].ToString();
                txtRetenido.Text = dtsPrecios.Rows[0]["precrete"].ToString();

            } 

                       
        }

Open in new window

0
 
NazoUKCommented:
It depends what your objective is. Using SelectedIndexChanged is the easiest way, whereas an ajax approach results in a nicer user experience but is more difficult to implement. I'm not sure the DynamicPopulate extender will do the job because you need to fill in multiple boxes so you might need to implement a custom solution.
0
 
edocolAuthor Commented:
the image shows what is to be done.  I'm expecting some example code according to provided code.
image-exp.JPG
0
All Courses

From novice to tech pro — start learning today.