By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,679 Members | 2,602 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,679 IT Pros & Developers. It's quick & easy.

selected item and dropdown list/listbox

P: n/a
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.
Nov 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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
-----Original Message-----
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.
.

Nov 17 '05 #2

P: n/a
Good evening,

after the bind do the following;
..ClearSelection()
..SelectedValue = ({Your value to find as string})

-----Original Message-----
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 oneof 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.
.

Nov 17 '05 #3

P: n/a
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, andsetting 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
-----Original Message-----
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 oneof 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.
.

.

Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.