Click here to Skip to main content
15,882,063 members
Please Sign up or sign in to vote.
4.33/5 (3 votes)
Hi All,

I have Table Name Account & i m binding a dropdownlist with this table
binding code is:

If IsPostBack = False Then
    Dim SqlAdapter As New SqlDataAdapter("Select AccountType,Cost From Accounts Where IsAddOn=1 order by AccountType ", ConnectionString)
    Dim SqlDataset As New DataSet
    DropDownList1.DataSource = SqlDataset.Tables(0)
    DropDownList1.DataTextField = "AccountType"
    DropDownList1.DataValueField = "Cost"
End If

problem is:
when I select either 5th, 8th or 9th item its shows 2nd item selected.

please suggest me where I am doing wrong
Updated 29-May-11 23:52pm
hoa20101988 30-May-11 5:33am    
you check dropdowm list
Ankur\m/ 30-May-11 5:33am    
How can a dropdownlist show 2 items at a time?
prateekfgiet 30-May-11 5:39am    
i m not saying that i m selecting 2 or more value at time,while i m selecting 5th its shows 2nd item selected same happen with 8th and 9th item
Ankur\m/ 30-May-11 5:55am    
I have added the clarification to the question.
The code seems fine to me. I still have a doubt. When you select the 5th (or other mentioned items) does the page posts back? Or these items do not get selected at all and it always automatically changes to 2nd item without page posting back to the server?
prateekfgiet 30-May-11 6:03am    
yes page goes to post back.

actually i have 2 text box where i print selected value,seleted index on selection change event.
when i select 5th(or other) text box shows 2nd item n drop down list also shows 2nd item selected

The item's most likely have the same value? If more than one item has the same value then will select the first item it comes to in the drop down list during postback. You need to make sure that each item in the DropDownList has a unique value. You may have to select the cost from the database during your postback event instead of using it as the DataValueField for the drop down list.
Share this answer
prateekfgiet 30-May-11 6:56am    
but the problem is, drop down text & value both are different at each item
rahkan 30-May-11 7:04am    
so no items in the list have the same cost? Have you tried running the select statement directly on the database to see what results you get back? Can you post those results?
prateekfgiet 30-May-11 7:06am    
hv few items with same value but its not happen only with same value item.
Ankur\m/ 30-May-11 7:08am    
No what he means is - check the "Cost" column returned by the database. Does it have same value for 5th, 8th and 9th item?
prateekfgiet 30-May-11 7:14am    
i got his point,
5th,8th item have same cost value but 9th have different cost value.
same problem with many other index what have different text as well as cost.
when i select either 5th, 8th or 9th item its shows 2 item selected
Does not make any sense. It's not related to your code above, all looks ok.

Not sure, how or why multiselected items are shown, may be you have put it to allow multiselect - if so, put it off. Please debug a little or share the values at 5th, 8th, 9th position as there must be something with those value selection it is happening. It's a specific issue only with you and probably code written is responsible.
Share this answer
prateekfgiet 30-May-11 5:42am    
i m saying that whn i m selecting 5th its shows 2nd item selected same happen with 8th and 9th item
Sandeep Mewara 30-May-11 5:49am    
Debug it. There is something in your code. This is not a normal or expected behavior and debug should help in narrow down the issue.
Ankur\m/ 30-May-11 5:49am    
multi-select in a drop down list???
Sandeep Mewara 30-May-11 6:09am    
Yep. By default, the user can only select one option.
But, using a 'MULTIPLE' attribute - user can select multiple options in a SELECT-OPTIONS html control.
Ankur\m/ 30-May-11 6:30am    
We do not have any such option in a asp dropdownlist which the user is using. Specifying multiple attribute in a select box will make it look like a asp Listbox which take more space.
I think I got the problem. The page posts back and there is something wrong in his page load event.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900