selected item and dropdown list/listbox

  • Thread starter Thread starter rohith
  • Start date Start date
R

rohith

Hope someone can help with this.

I am trying to add items to a drop down list from a
database. I can do this fine by using the bind method.
What I want to do also is to set the selected item to one
of those values. Using Asp 3.0 I could use the While
Wend loop to see if the value from the database equals
the variable and if so make this the selected item

While
If rs("x") = x Then
<option selected>rs("x")</option>
End If
Wend

Is there similar code in Asp.net

Thank you in advance.
 
Rohith,

This is what i normally do, and it works fine for me.
Comparing the value to the value in dropdownlist box, and
setting the SelectedIndex property to the current counter.

Here ProjectItemType is the dropdownlist box.

----------------------------------------------------------
For ItemTypeCounter = 0 To ProjectItemType.Items.Count - 1
If ProjectItemType.Items(ItemTypeCounter).Value
= "Value" Then

ProjectItemType.SelectedIndex = ItemTypeCounter
Exit For
End If
Next ItemTypeCounter
 
Good evening,

after the bind do the following;
..ClearSelection()
..SelectedValue = ({Your value to find as string})
 
Thank you very much, this works.

-----Original Message-----
Rohith,

This is what i normally do, and it works fine for me.
Comparing the value to the value in dropdownlist box, and
setting the SelectedIndex property to the current counter.

Here ProjectItemType is the dropdownlist box.

--------------------------------------------------------- -
For ItemTypeCounter = 0 To ProjectItemType.Items.Count - 1
If ProjectItemType.Items(ItemTypeCounter).Value
= "Value" Then

ProjectItemType.SelectedIndex = ItemTypeCounter
Exit For
End If
Next ItemTypeCounter
---------------------------------------------------------

Thanks,

Tapasvi

.
 
Back
Top