Jump to content
Sign in to follow this  
startuga

[Resolvido] DropdownList

Recommended Posts

startuga

Boas,

Alguém me sabe indicar porque é que uma dropdownlist que está a receber valores vindos de uma BD, está a reconhcer o primeiro valor da como sendo = 0 quando na BD ele é = 1.

:confused:

Obrigado

Share this post


Link to post
Share on other sites
startuga

   Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
       If Not IsPostBack Then
           Dim strAreaCod As String = Request.QueryString("AREA_ID")

           DropDownList1.SelectedIndex = strAreaCod

       End If
   End Sub

Protected Sub btn_update_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_update.Click

       Dim con As New SqlConnection("Data Source=xxxxxxx;Initial Catalog=xxxxxxx;User ID=xxxxxxx;pwd=xxxxxx")
       con.Open()
       Dim command As New SqlCommand("UPDATE CLUSTERS SET Cluster_ID = @Cluster_ID, Cluster_Name = @Cluster_Name, AREA_ID = @AREA_ID, Cluster_ENABLE = @Cluster_ENABLE FROM CLUSTERS INNER JOIN AREAS ON CLUSTERS.AREA_ID = AREAS.AREA_ID WHERE (CLUSTERS.Cluster_ID = @Cluster_ID)", con)

       command.Parameters.Add("@AREA_ID", SqlDbType.VarChar).Value = DropDownList1.SelectedIndex

       command.ExecuteNonQuery()
       con.Close()
   End Sub
End Class

Edited by ribeiro55

Share this post


Link to post
Share on other sites
nelsonr

O SelectedIndex é a posição da opção selecionada, começando no 0 para a primeira opção.

Como é que preencheste a dropdown?

Provavelmente o que pretendes é o .SelectedValue

Share this post


Link to post
Share on other sites
startuga

.SelectValue resultou.

Obrigado :)

A minha resistência a este tipo de erros ainda está muito baixa :confused:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.