Ver Mensaje Individual
  #12 (permalink)  
Antiguo 14/12/2012, 01:11
maialenlopez
 
Fecha de Ingreso: abril-2012
Mensajes: 449
Antigüedad: 12 años, 1 mes
Puntos: 7
Respuesta: obtener valor del dropdownlist

Hola;

Voy a poner todo el código de nuevo para haber si me podéis echar una mano que es que lo necesito urgente.

Lo que necesito es, una vez que el usuario haya elegido una de las opciones del combobox, coger el valor de ese combobox.

HojaLiquidacionGastos.aspx
Código ASP:
Ver original
  1. <%@ Page Title="Hoja de Liquidacion Gastos" Language="vb" MasterPageFile="~/Site.Master" AutoEventWireup="false" CodeBehind="HojaLiquidacionGastos.aspx.vb" Inherits="HojaDeGastos.HojaLiquidacionGastos" %>
  2.  
  3. <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
  4. </asp:Content>
  5. <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
  6.     <h2>
  7.         HOJA DE LIQUIDACIÓN DE GASTOS
  8.     </h2>
  9.     <p>
  10.         DEPARTAMENTO:
  11.         <asp:DropDownList ID="ComboBoxDepartamentoLG" runat="server"
  12.             Enabled = "True" Height="25px" Width="197px" BackColor="#CCCCCC" AutoPostBack="True">
  13.         </asp:DropDownList>
  14.     </p>
  15. </asp:Content>

HojaLiquidacionGastos.aspx.vb
Código vb.net:
Ver original
  1. Imports System.Web
  2. Imports System.Web.Configuration
  3. Imports System.Data
  4. Imports System.Data.SqlClient
  5.  
  6. Public Class HojaLiquidacionGastos
  7.     Inherits System.Web.UI.Page
  8.  
  9.     Dim iva As String = "1180"
  10.  
  11.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  12.         cargarComboBoxDepartamento()
  13.     End Sub
  14.  
  15.     Protected Sub cargarComboBoxDepartamento()
  16.         Dim conn As New SqlConnection(WebConfigurationManager.ConnectionStrings("conexion").ConnectionString)
  17.  
  18.         Dim comm1 As SqlCommand = New SqlCommand("SELECT * " & _
  19.                                                 "FROM dbo.temp_departamento", conn)
  20.         Dim reader1 As New SqlDataAdapter(comm1.CommandText, conn)
  21.  
  22.         Dim ds As New DataSet
  23.  
  24.         Try
  25.  
  26.             conn.Open()
  27.  
  28.             reader1.Fill(ds)
  29.  
  30.             ComboBoxDepartamentoLG.DataSource = ds
  31.             ComboBoxDepartamentoLG.DataValueField = "id_dept"
  32.             ComboBoxDepartamentoLG.DataTextField = "nombre_dept"
  33.             ComboBoxDepartamentoLG.DataBind()
  34.  
  35.         Catch ex As Exception
  36.             MsgBox("Error en BD" & Chr(13) & Chr(13) & ex.Message)
  37.         Finally
  38.             If conn.State = ConnectionState.Open Then
  39.                 conn.Close()
  40.                 conn.Dispose()
  41.             End If
  42.         End Try
  43.     End Sub
  44.  
  45.     Protected Sub BtnGuardarLG_Click(ByVal sender As Object, ByVal e As EventArgs) Handles BtnGuardarLG.Click
  46.         Dim dept As Integer
  47.         dept = ComboBoxDepartamentoLG.SelectedValue
  48.     End Sub

Esto es lo que tengo en el aspx y en el aspx.vb. Si os fijais el comobobox lo tengo puesto como AutoPostBack="True". Si lo pongo a "true" por mucho que elija por ejemplo la tercera opción del combobox, una vez seleccionada se me vuelve a colocar en el combo la primera opción.

Ya no se que hacer mas.
__________________
Gracias por todo;

Un saludo