Dropdown list box.....

S

San Smith

I have a dropdown list box with list of item. When I read the data from
database I want to display that value(one of the item in the drop down box)
in the dropdown list box.
How to do that in a dropdown list box ?
San
 
G

George

I think you can add an item to your DropDown list by:

DrpList.Items.Add(New ListItem(strVar1,strVar2))

The strVar1 is the Text, and strVar1 is the Value. I believe if you leave strVar2 out, the Value
will default to strVar1.

If you need to replace an existing item in a specific index location, I think you can use:

DrpList.Item.Items(ndx).Text = strVar1
DrpList.Item.Items(ndx).Value = strVar2

I'm pretty sure there must be an list item already at the ndx location, though.

George
 
S

San Smith

George,
I already have an index item in the list box.How to set the existing index
item to display ?
San
 
S

San Smith

If I have several items in the drop down list box(driven by database), is
there anyway of identifying a particular items index number. If so.... Then
I an set SelectedIndex number.
I appriciate your help
San.
 
G

George

I haven't gotten into db's, yet, so can't help you with that one.

My list items are in an array, and the array index is the same as the list index, so it works out
well.

George
 
P

Paul

San, in your code-behind you have an events for the list, such as
SelectedIndexChanged. That gets fired when a user selects a new item
from the list. You can use the event to trap the index of the list item
like this:

Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
DropDownList1.SelectedIndexChanged

Dim foo As Integer
DropDownList1.SelectedIndex = foo

End Sub


Of course the list also has a Load event and a DataBinding event where
you could grab the index too (although it may always be zero.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top