Solved

Dropdownlist selection problem

Posted on 2004-10-17
17
280 Views
Last Modified: 2008-02-01
Hi experts,

I have the following code

app_f1_maj1.Items.FindByValue("   ").Selected = True
app_f1_maj1.ClearSelection()
app_f1_maj1.Items.FindByValue(Session("f1_maj1")).Selected = True

After executing the third line I get the message "A DropDownList cannot have multiple items selected"

I checked the selected value of app_f1_maj1 after the ClearSelection and it pointed to "   "...............any ideas???
0
Comment
Question by:sylo_y
  • 10
  • 6
17 Comments
 
LVL 6

Expert Comment

by:casstd
ID: 12336557
Hi,

       if Trim(session("f1_Maj1")) <> "" then
            app_f1_maj1.Items.FindByValue(Session("f1_maj1")).Selected = True
       else
              app_f1_maj1.Items.FindByValue("   ").Selected = True
       end if

Hope this would be helpful to you.
0
 

Author Comment

by:sylo_y
ID: 12336657
Thanks a lot but this will not solve the problem.....The lines are not after each other as in the code but when I trace the values even if I choose to clear the selection the value "   " is always selected and when I try to select another one I will have two selected and that's why I get the error!!!!!!!!!!!!!!!!!!!!!
0
 
LVL 1

Expert Comment

by:adktd
ID: 12337261
Hi. First of all,are we talking about a dynamic combo box or something non dynamic?

Show me the code of the combo box show i'll give u a spesified answer.
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

Author Comment

by:sylo_y
ID: 12344944
Well it is a dynamic dropdown list box....

  Bus = New BusObjVB
  dset = New DataSet
  dset = Bus.get_all_maj(app_fac1.SelectedItem.Value, app_type)
  app_f1_maj1.Items.Add(New ListItem("   ", "   "))
   For i = 0 To dset.Tables("m").Rows.Count - 1
         li = New System.Web.UI.WebControls.ListItem
         li.Value = dset.Tables("m").Rows(i)("mc").ToString
         li.Text = dset.Tables("m").Rows(i)("mt").ToString
         app_f1_maj1.Items.Add(li)
   Next

get_all_maj is a function that queries a table and return the records in a dataset

Function get_all_maj(ByVal fac As String, ByVal typ As String) As DataSet
      Dim da As OdbcDataAdapter
      Dim ds As New DataSet
      Dim myConnection As New OdbcConnection(_connStr)
      Dim myselectquery As String

      'Sorry but I cannot reveal the query
     
       myselectquery = "SELECT .............."
     
       da = New OdbcDataAdapter(myselectquery, myConnection)
       da.Fill(ds, "m")
       Return ds
End Function


Let me point out that the creation and filling of the dropdownlist is correct ...again I traced it and checked each value and the value of Session("f1_maj1") is between them but when this code

app_f1_maj1.Items.FindByValue("   ").Selected = True
app_f1_maj1.ClearSelection()
app_f1_maj1.Items.FindByValue(Session("f1_maj1")).Selected = True

is executed as if the third line has no effect ............. weird!!
0
 
LVL 1

Expert Comment

by:adktd
ID: 12344996
ok i whould advice u to do this the way i do it and it always works.No matter what are the values of your combo box leave the first line blank with the value -1.So instead of clearing the selection u should select the first line which has nothing.
0
 

Author Comment

by:sylo_y
ID: 12345247
Ok I did that but if I choose another line without clearing the selection I will have two values selected and the one that will display is the first which is an empty line ....and this is not what I want
0
 

Author Comment

by:sylo_y
ID: 12345461
Please i need a solution..........
0
 

Author Comment

by:sylo_y
ID: 12346199
Ok I'll remodify my question since I changed a bit in the code and what I have now is the following

I have two pages, the data entered in thoses pages are saved in session variables so that when I move from one to the other I can set the values of the various objects on those pages to what I selected.  

My problem is on one page where I have two DDL.  
One is dependant on the other.  
The first time I choose a value in the first DDL the values in the second are filled depending on the first and I choose an entry which is saved in a session variable called f1_maj1.  The second time I get to the same page --and here I am loading the page again since this is not a postback and filling the second DDL based on the value of the first DDL-- the value of the first drop down list is set correctly and the second one has the correct items in it but with the first element selected which has index 0 while the item I want selected has a different index.

To set the value of the second DDL this is the code

app_f1_maj1.ClearSelection()
app_f1_maj1.Items.FindByValue(Session("f1_maj1")).Selected = True

I debuged my code with Session("f1_maj1") having a value of "4".  In the second drop down list I have this value and it is being selected -- since I checked app_f1_maj1.items(5).selected and it had a value of TRUE-- but on page render the second DDL is showing the item with index 0....

Please this is very urgent...

Thanks for your reply.
0
 

Author Comment

by:sylo_y
ID: 12346410
I'll even increase the point value of this question
0
 
LVL 1

Expert Comment

by:adktd
ID: 12347315
Everytime i want to preselect a spesific value on addl i do the following :

Write a vbscript code on Window_OnLoad sub in the client and write a code like this :

if f_company.txtSelComType.value <> "" then
    for m = 0 to f_company.selComType.length - 1
       if LineParse("ID", f_company.selComType(m).value, "|") = f_company.txtSelComType.value   then ''That's the value i want
       f_company.selComType(m).selected = true
       exit for
      end if
   next
end if
0
 

Author Comment

by:sylo_y
ID: 12355539
This solution can't work in my case since first  have  asession varaibale to comapre to and second my form is dynamically generated
0
 
LVL 1

Expert Comment

by:adktd
ID: 12356225
yeah i know i that's why every time i enter the page the vars i want to compare are sores to a hidden field. In the prev code, f_company.txtSelComType.value  is a hidden field.
0
 

Author Comment

by:sylo_y
ID: 12356238
Ok I've tried something, originally setting this ddl value was done on Page_load so i placed the code in  another procedure that was triggered when I change the value of the first DDL......this works but what i need is to see the value in the 2nd ddl when the page loads how to do that?????????  Hope this was clear......
0
 
LVL 1

Expert Comment

by:adktd
ID: 12356737
if u did that with the one ddl why can't u do it with the 2nd one as well?
What do u need in order to make the 2nd ddl select the correct line?
Do u need a variable that u pass in that page?
0
 

Author Comment

by:sylo_y
ID: 12357575
Hi adktd.....I solved the problem and it was related to the way I was binding the data .....I use two ways and it seems that one of them in this case doesn't work so when I tried the second way it worked ......eventhough the first ddl uses the other method but works just fine........I know it is not a logical solution but it worked like  a charm ...........
Thanks for your help
0
 
LVL 1

Accepted Solution

by:
adktd earned 500 total points
ID: 12358895
I hope i helped u to find a solution.
What do u plan to do about the questions points?
0
 

Author Comment

by:sylo_y
ID: 12366808
I won't be stingy...........so I'll give you those 500 points and thanks for your help....
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question