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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can I substitute value for index in dropdown list

Status
Not open for further replies.

Theseekers

Technical User
Jul 22, 2004
118
0
0
US
Hello Tekers,

Hope every1 has a great Christmas and New Year.

I have a basic question displaying value of dropdown box and would like to find out a general method to handle large amount of them.

My situation.

A form has about 60 of these dropdown mostly contain 3 to 4 items. On the data entry portion, I am ok with them. My question is in the update procedure when I need to load them back in. For example, in data entry one can just select the item in the box and its index saved in the db. When I bring them back; the index value is display.

I have been using the case in the SQL statement to substitute the index for the display value, but this is ok for small size and # of dropbox. I don't think this is efficient with 60+.

Does any1 has any suggestion how I might tackle this problem?? If you do please share, and I really appreciate your input & direction.

TIA
 
You don't need to substitute the index for the display value on each ListItem. All you need to do is set the relevant Text and Value members. For example, if your SQL Query returns to columns (where Column1 is the value, and Column2 is the Text to display) then you just need to set the following attributes:
Code:
        DropDownList1.DataSource = ds.Tables(0)
        DropDownList1.DataValueField = "Column1"
        DropDownList1.DataTextField = "Column2"
        DropDownList1.DataBind()


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Thanks for your speedy response Ca8msm,

However, my dropdown boxes was not draw information from a table. Due to this situation, these lists are static (no changes in them for good);therefore, I use the collection property to build them. You suggestion would certainly work on my next project and not for this one.

Let me clarify it a little bit.

I have a huge table containing information of these dropdown indexes + others. On the update portion, I issues a select statement to get the value off the db for these boxes so I can display them on the form. When I do this, all I see is 1, 2, -1 (yes/no/blank). As I have said prev, in the sql for the datasource; I use the case to associate these indexes with their values ('Field1' = case when Field1 = '-1' then '' when Field1 = '1' then 'Yes' else 'No' end). This would display Yes if the value of the db = 1 etc.

How can I do similar thing for 60+ boxes???.

How about let them be loaded with the actual value from db and then loop through them to correct the right display value???

I am looking at the findbyvalue to see if I can do this programatically.

Any suggestion????

Thanks for all of your input.
 
I'm not sure I understand. In your first paragraph you say:
my dropdown boxes was not draw information from a table...I use the collection property to build them
then, you say:
I issues a select statement to get the value off the db for these boxes so I can display them on the form
So which is it? Does the data come from a database (in which case you just return two columns and set the Text and Value members like I stated above e.g. 1, Yes) or does it come from a collection (in which case it shouldn't be any different as long as you return two columns).


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Hi,

Ok let me try out something with your suggestion to see I can get it going.

Thanks
 
Code:
ddown.SelectedIndex = ddown.Items.IndexOf(ddown.Items.FindByValue(1))

is this what you're looking for?

"...we both know I'm training to become a cagefighter...see what happens if you try 'n hit me..."
 
Thank Checkai

I will try this later today.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top