Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with two dropdownlist

Status
Not open for further replies.

sirpelon

Programmer
Sep 13, 2001
19
0
0
MX
Hi

I have two dropdownlist in a page that represents the years of a period, in some part of my code i have this

ddlAnoInicio.Selectedvalue=adoDatos.Item("ano_inicio").Tostring
ddlAnoFin.Selectedvalue = adoDatos.Item("ano_fin").Tostring

adodatos is a SqlDataReader

The problem is that when the selectedvalue of the second ddl is assigned, the value of the first ddl is changed to the same value. For example

First ddl must be 1994
Second ddl must be 2000

When the values are assigned both ddl have the value of 2000

Please i need your help
 
hi,
this is one of those problems where it is doing exactely what you are telling it to do.

Here is what I would start with:

Are
adoDatos.Item("ano_inicio").Tostring
adoDatos.Item("ano_fin").Tostring
Actually Different?

step through the debugger and watch the values get set.

next I would make sure that you are not reassigning the value anywhere else.

Try hardcoding the values and see if they change.

next I would make sure that your Selected values are the same as your Selected text.

Next I would make sure that you do not have the same ID or Name on your controls.

just a quick washlist,

HTH

bassguy
 
Thanks for your reply bassguy

I figured out, previous to the code i posted, i populate the ddls with a loop incrementing the year, i used a listitem object for both ddl's, and in some way the get related, that's why the value of one ddl reply to the other.

Something like this for the populate procedure

Dim lstElemento As New ListItem
lstElemento.Value = CStr(intAno)
lstElemento.Text = CStr(intAno)
-> ddlAnoInicio.Items.Add(lstElemento)
-> ddlAnoFin.Items.Add(lstElemento)
lstElemento = Nothing

I used another listelement object and everything going Ok.

 
sirpelon,

You are correct in identifying that it is because you used the same listitem as to why the values were the same - but rather than create multiple listitem objects, you can just create a new instanct of the same object. e.g.
Code:
        Dim li As ListItem
        Dim i As Integer

        For i = 0 To 10
            li = New ListItem
            li.Text = i
            li.Value = i
            ListBox1.Items.Add(li)
        Next

If you are only planning on two items then it is not such a big deal, but if you plan on creatting a lot then I would suggest doing what I have shown in the example above.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top