Solved

Dropdownlist selection problem

Posted on 2004-10-17
17
283 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Call a function within the ASP code 4 30
Adding Row and Cell on a table 14 32
Validating Date 4 37
Update the value of table B with value of table A tables inner join 6 95
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…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

738 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