473,412 Members | 2,027 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

selected item and dropdown list/listbox

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
3 2821
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Peter Moscatt | last post by:
I am having trouble understanding the methods for the Listbox from Tk. If I was to select at item in the list using a mouse click (have already created the bind event) - what method returns the...
5
by: Kris Rockwell | last post by:
Hello (again), I have gotten the dropdown list functionality to work through a few tricks (probably not the most efficient, but it works) but I am not sure how to set the default selected value....
6
by: Jenna Alten | last post by:
I have a datagrid with a template column that contains a dropdown list. I currently fill and display the dropdown list on the page load. This is working correctly. I am NOT using an Edit Column. I...
1
by: Karen Grube | last post by:
Hi! I'm using a standard server side ASP.Net listbox control on a web form. The page is basically various shades of green. The listbox itself has a pale green background and forest green text...
1
by: acord | last post by:
Hi, I am having problem to get a value of the selected item from a dropdown listbox. Here is the JS function; function getSelectedItem(objSelect) { alert("in getSelectedItem"); alert...
2
by: John | last post by:
I have a listbox that is databound when my form loads. A user can then select and option using a drop down box. When the user selects an option the corresponding items in the listbox gets selected....
2
by: Hitesh | last post by:
I have a listbox and the values get selected (highlighted) from code. I can highlight the corresponding list box items, but they do not show in the listbox I have to scroll through the list box to...
11
by: Santosh | last post by:
Dear all , i am writting following code. if(Page.IsPostBack==false) { try { BindSectionDropDownlist();
6
by: yasodhai | last post by:
Hi, I used a dropdown control which is binded to a datagrid control. I passed the values to the dropdownlist from the database using a function as follows in the aspx itself. <asp:DropDownList...
3
by: peter.mosley | last post by:
I've tried googling for the answer to this problem, without any luck. I'm sure the truth must be out there somewhere! I have a multiselect listbox populated with many items (set by the RowSource...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.