Foros del Web » Programación para mayores de 30 ;) » .NET »

[SOLUCIONADO] ir creando según el usuario vaya introduciendo

Estas en el tema de ir creando según el usuario vaya introduciendo en el foro de .NET en Foros del Web. Hola estoy haciendo una aplicación web y necesito vuestra ayuda para realizar esto ya que no se ni por donde empezar. os explico; tengo un ...
  #1 (permalink)  
Antiguo 28/02/2013, 03:53
 
Fecha de Ingreso: abril-2012
Mensajes: 449
Antigüedad: 12 años
Puntos: 7
Pregunta ir creando según el usuario vaya introduciendo

Hola estoy haciendo una aplicación web y necesito vuestra ayuda para realizar esto ya que no se ni por donde empezar.

os explico; tengo un .aspx en el que tengo lo siguiente:
Código aspx:
Ver original
  1. <%@ Page Title="Hoja de Visas" Language="vb" MasterPageFile="~/Site.Master" AutoEventWireup="false" CodeBehind="HojaVisas.aspx.vb" Inherits="HojaDeGastos.HojaVisas" %>
  2.  
  3. <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
  4. </asp:Content>
  5. <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
  6. <asp:DropDownList ID="ComboConceptosV1" runat="server" Height="25px"
  7.             Width="175px" AutoPostBack="True">
  8.         </asp:DropDownList>
  9.         &nbsp;
  10.         <asp:Label ID="Label1" runat="server" Text="Descripción: "></asp:Label>
  11.         <asp:TextBox ID="TextDescripcionV1" runat="server" BackColor="#CCCCCC"
  12.             Width="190px"></asp:TextBox>
  13.         &nbsp;
  14.         <asp:Label ID="Facturable1" runat="server" Text="Facturable: "></asp:Label>
  15.         <asp:RadioButtonList ID="RadioButtonFacturableV1" runat="server" AutoPostBack="True" RepeatDirection="Horizontal" RepeatLayout="Flow" CellPadding="-1" Enabled="False">
  16.             <asp:ListItem Value="1">SI</asp:ListItem>
  17.             <asp:ListItem Value="2">NO</asp:ListItem>
  18.         </asp:RadioButtonList>
  19.         <asp:Label ID="Label2" runat="server" ForeColor="Red" Font-Bold="True"></asp:Label>
  20.         &nbsp;
  21.         <asp:Label ID="Orden1" runat="server" Text="Orden: "></asp:Label>
  22.         <asp:TextBox ID="TextOrdenV1" runat="server" BackColor="#CCCCCC" Width="90px"
  23.             Enabled="True" AutoPostBack="True"></asp:TextBox>
  24.         &nbsp;
  25.         <asp:Label ID="Proyecto1" runat="server" Text="Proyecto: "></asp:Label>
  26.         <asp:TextBox ID="TextProyectoV1" runat="server" BackColor="#CCCCCC" Width="80px"
  27.             Enabled="True" AutoPostBack="True"></asp:TextBox>
  28.         &nbsp;
  29.         <asp:Label ID="Importe1" runat="server" Text="Importe: "></asp:Label>
  30.         <asp:TextBox ID="TextImporteV1" runat="server" BackColor="#CCCCCC" Width="50px"
  31.             Enabled="True" AutoPostBack="True"></asp:TextBox>
  32.         <asp:Label ID="validacionImporteV1" runat="server" ForeColor="Red" Font-Bold="True"></asp:Label>
  33.         &nbsp;
  34. </asp:Content>

Lo que quiero es que todo lo que he puesto en el codigo .aspx se vaya creando automaticamente. Es decir, que si un usuario termina de introducir en el Importe1 un valor, que me genere de nuevo todo (ComboConceptosV1, label1, TextDescripcionV1, ... ) hasta llegar al validacionImporteV1.

¿alguien tiene alguna idea de como hacerlo?
__________________
Gracias por todo;

Un saludo
  #2 (permalink)  
Antiguo 28/02/2013, 08:21
 
Fecha de Ingreso: abril-2012
Mensajes: 449
Antigüedad: 12 años
Puntos: 7
Respuesta: ir creando según el usuario vaya introduciendo

Cita:
Iniciado por maialenlopez Ver Mensaje
Hola estoy haciendo una aplicación web y necesito vuestra ayuda para realizar esto ya que no se ni por donde empezar.

os explico; tengo un .aspx en el que tengo lo siguiente:
Código aspx:
Ver original
  1. <%@ Page Title="Hoja de Visas" Language="vb" MasterPageFile="~/Site.Master" AutoEventWireup="false" CodeBehind="HojaVisas.aspx.vb" Inherits="HojaDeGastos.HojaVisas" %>
  2.  
  3. <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
  4. </asp:Content>
  5. <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
  6. <asp:DropDownList ID="ComboConceptosV1" runat="server" Height="25px"
  7.             Width="175px" AutoPostBack="True">
  8.         </asp:DropDownList>
  9.         &nbsp;
  10.         <asp:Label ID="Label1" runat="server" Text="Descripción: "></asp:Label>
  11.         <asp:TextBox ID="TextDescripcionV1" runat="server" BackColor="#CCCCCC"
  12.             Width="190px"></asp:TextBox>
  13.         &nbsp;
  14.         <asp:Label ID="Facturable1" runat="server" Text="Facturable: "></asp:Label>
  15.         <asp:RadioButtonList ID="RadioButtonFacturableV1" runat="server" AutoPostBack="True" RepeatDirection="Horizontal" RepeatLayout="Flow" CellPadding="-1" Enabled="False">
  16.             <asp:ListItem Value="1">SI</asp:ListItem>
  17.             <asp:ListItem Value="2">NO</asp:ListItem>
  18.         </asp:RadioButtonList>
  19.         <asp:Label ID="Label2" runat="server" ForeColor="Red" Font-Bold="True"></asp:Label>
  20.         &nbsp;
  21.         <asp:Label ID="Orden1" runat="server" Text="Orden: "></asp:Label>
  22.         <asp:TextBox ID="TextOrdenV1" runat="server" BackColor="#CCCCCC" Width="90px"
  23.             Enabled="True" AutoPostBack="True"></asp:TextBox>
  24.         &nbsp;
  25.         <asp:Label ID="Proyecto1" runat="server" Text="Proyecto: "></asp:Label>
  26.         <asp:TextBox ID="TextProyectoV1" runat="server" BackColor="#CCCCCC" Width="80px"
  27.             Enabled="True" AutoPostBack="True"></asp:TextBox>
  28.         &nbsp;
  29.         <asp:Label ID="Importe1" runat="server" Text="Importe: "></asp:Label>
  30.         <asp:TextBox ID="TextImporteV1" runat="server" BackColor="#CCCCCC" Width="50px"
  31.             Enabled="True" AutoPostBack="True"></asp:TextBox>
  32.         <asp:Label ID="validacionImporteV1" runat="server" ForeColor="Red" Font-Bold="True"></asp:Label>
  33.         &nbsp;
  34. </asp:Content>

Lo que quiero es que todo lo que he puesto en el codigo .aspx se vaya creando automaticamente. Es decir, que si un usuario termina de introducir en el Importe1 un valor, que me genere de nuevo todo (ComboConceptosV1, label1, TextDescripcionV1, ... ) hasta llegar al validacionImporteV1.

¿alguien tiene alguna idea de como hacerlo?

He conseguido crear que dandole a un boton me genere textbox y labels pero necesito tambien que me genere combobox y radiobutton.

¿Como puedo hacerlo?

Código vb.net:
Ver original
  1. Private Property QuantityDinamicControls() As Integer
  2.         Get
  3.             If ViewState("Quantity") = Nothing Then
  4.                 ViewState("Quantity") = 0
  5.             End If
  6.  
  7.             Return DirectCast(ViewState("Quantity"), Integer)
  8.  
  9.         End Get
  10.  
  11.         Set(ByVal value As Integer)
  12.             ViewState("Quantity") = value
  13.         End Set
  14.     End Property
  15.  
  16.     Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
  17.  
  18.         Me.QuantityDinamicControls += 1
  19.         Me.validacionHojaVisas.Text = ViewState("Quantity")
  20.  
  21.     End Sub
  22.  
  23.     Protected Overloads Overrides Sub CreateChildControls()
  24.  
  25.         If Page.IsPostBack Then GenerateControls()
  26.  
  27.     End Sub
  28.  
  29.     Private Sub GenerateControls()
  30.  
  31.         Dim Quantity As Integer = 0
  32.         While Quantity <= Me.QuantityDinamicControls
  33.             Dim concepto As New
  34.             Dim txt1, txt2, txt3, txt4 As New TextBox()
  35.             Dim descripcion, facturable, orden, proyecto, importe As New Label()
  36.  
  37.  
  38.             descripcion.Attributes.Add("style", "margin-bottom: 10px")
  39.             descripcion.ID = "descricion" + (Quantity + 1).ToString()
  40.             descripcion.Text = "Descripción:"
  41.             txt1.Attributes.Add("style", "margin-bottom: 10px")
  42.             txt1.ID = "txt1" + (Quantity + 1).ToString()
  43.             txt1.Text = "Descripción..."
  44.  
  45.             facturable.Attributes.Add("style", "margin-bottom: 10px")
  46.             facturable.ID = "facturable" + (Quantity + 1).ToString()
  47.             facturable.Text = "Facturable:"
  48.  
  49.             orden.Attributes.Add("style", "margin-bottom: 10px")
  50.             orden.ID = "orden" + (Quantity + 1).ToString()
  51.             orden.Text = "Orden:"
  52.             txt2.Attributes.Add("style", "margin-bottom: 10px")
  53.             txt2.ID = "txt2" + (Quantity + 1).ToString()
  54.             txt2.Text = "Orden..."
  55.  
  56.             proyecto.Attributes.Add("style", "margin-bottom: 10px")
  57.             proyecto.ID = "proyecto" + (Quantity + 1).ToString()
  58.             proyecto.Text = "Proyecto:"
  59.             txt3.Attributes.Add("style", "margin-bottom: 10px")
  60.             txt3.ID = "txt3" + (Quantity + 1).ToString()
  61.             txt3.Text = "Proyecto..."
  62.  
  63.             importe.Attributes.Add("style", "margin-bottom: 10px")
  64.             importe.ID = "importe" + (Quantity + 1).ToString()
  65.             importe.Text = "Importe:"
  66.             txt4.Attributes.Add("style", "margin-bottom: 5px")
  67.             txt4.ID = "txt4" + (Quantity + 1).ToString()
  68.             txt4.Text = "Importe..."
  69.  
  70.             phDinamicControls.Controls.Add(descripcion)
  71.             phDinamicControls.Controls.Add(txt1)
  72.             phDinamicControls.Controls.Add(facturable)
  73.             phDinamicControls.Controls.Add(orden)
  74.             phDinamicControls.Controls.Add(txt2)
  75.             phDinamicControls.Controls.Add(proyecto)
  76.             phDinamicControls.Controls.Add(txt3)
  77.             phDinamicControls.Controls.Add(importe)
  78.             phDinamicControls.Controls.Add(txt4)
  79.             phDinamicControls.Controls.Add(New LiteralControl("<br/>"))
  80.             Quantity += 1
  81.         End While
  82.  
  83.     End Sub
  84.  
  85.     Private Function GetTxtControls() As String
  86.         Dim sb As New StringBuilder
  87.         Dim i As Integer = 0
  88.  
  89.         While i <= Me.QuantityDinamicControls
  90.             Dim descripcion As String = "descripcion" + (i + 1).ToString()
  91.             Dim facturable As String = "facturable" + (i + 1).ToString()
  92.             Dim orden As String = "orden" + (i + 1).ToString()
  93.             Dim proyecto As String = "proyecto" + (i + 1).ToString()
  94.             Dim importe As String = "importe" + (i + 1).ToString()
  95.             Dim txt1 As String = "txt1" + (i + 1).ToString()
  96.             Dim txt2 As String = "txt2" + (i + 1).ToString()
  97.             Dim txt3 As String = "txt3" + (i + 1).ToString()
  98.             Dim txt4 As String = "txt4" + (i + 1).ToString()
  99.             Dim descripcionControl As TextBox = TryCast(phDinamicControls.FindControl(descripcion), TextBox)
  100.             Dim facturableControl As TextBox = TryCast(phDinamicControls.FindControl(facturable), TextBox)
  101.             Dim ordenControl As TextBox = TryCast(phDinamicControls.FindControl(orden), TextBox)
  102.             Dim proyectoControl As TextBox = TryCast(phDinamicControls.FindControl(proyecto), TextBox)
  103.             Dim importeControl As TextBox = TryCast(phDinamicControls.FindControl(importe), TextBox)
  104.             Dim txtControl1 As TextBox = TryCast(phDinamicControls.FindControl(txt1), TextBox)
  105.             Dim txtControl2 As TextBox = TryCast(phDinamicControls.FindControl(txt2), TextBox)
  106.             Dim txtControl3 As TextBox = TryCast(phDinamicControls.FindControl(txt3), TextBox)
  107.             Dim txtControl4 As TextBox = TryCast(phDinamicControls.FindControl(txt4), TextBox)
  108.  
  109.             sb.Append(descripcionControl.Text & "<br />")
  110.             sb.Append(facturableControl.Text & "<br />")
  111.             sb.Append(ordenControl.Text & "<br />")
  112.             sb.Append(proyectoControl.Text & "<br />")
  113.             sb.Append(importeControl.Text & "<br />")
  114.             sb.Append(txtControl1.Text & "<br />")
  115.             sb.Append(txtControl2.Text & "<br />")
  116.             sb.Append(txtControl3.Text & "<br />")
  117.             sb.Append(txtControl4.Text & "<br />")
  118.  
  119.             i += 1
  120.         End While
  121.  
  122.         Return sb.ToString
  123.  
  124.     End Function
__________________
Gracias por todo;

Un saludo

Etiquetas: creando, según, server, usuario
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 13:27.