Click to See Complete Forum and Search --> : List Objects With DropDownList


ABudair
October 21st, 2003, 07:59 AM
Hello everybody;

I want to ask if i could use the DropDownList as default combox , and in other words i want to add an object with two vars id and name, and everybody knows that in vb.net there is a way to do it by add it simply to combobox. like

dim i as long

for i=0 to ds.tables(0).rows.count -1

ObjlistItem = new ListItem (ds.tables(0).Rows(i).item(Id), _
ds.tables(0).item(Name).ToString)

comboboxName.Items.Add(ObjListItem )

next

but i can't do it in asp.net in drop down list control because drop down list doesn't accept object to add at all.

wt do you think.

any way your reply thanks alot

Ahmed Bedair.

poochi
October 21st, 2003, 11:40 AM
DropDownList webcontrol does accept "ListItem" object. I tried the following codes which works fine in my machine.


'DL1 is the dropdownlist control variable.
Dim obj as Object
obj = new ListItem("displaytext", "value")
DL1.Items.Add(obj)



DL1.Items.Add(new ListItem("displaytext", "value"))



Dim obj as ListItem
obj = new ListItem("displaytext", "value")
DL1.Items.Add(obj)


ListItem object has 3 overloaded constructors. 1. Default/empty constructor 2. takes only one parameter (displaytext) 3. takes 2 parameters (displaytext & value).