473,785 Members | 2,414 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ListBox selected item

Hello all, I am trying to go through a ListBox and verify if am item was
selected. If an item was selected, I would like to get a handle of the item

and simply do a response.write on the selected handle. The issue that I am

facing is that I am going each item, but my code does not catch the selected

item. Can anyone please take a look at the code and let me know what I am
doing wrong.

If listBox1.Items. Count > 0 Then
For intCount = 0 To listBox1.Items. Count - 1
If listBox1.Select edIndex = True Then
Response.Write( listBox1.Select edIndex)
End If
Next
End If
B.T.W. this is the way the listBox is defined in the .NET HTML page:

<asp:listbox id="listBox1" runat="server" Width="200px"
Height="142px"> </asp:listbox><BR >
Nov 19 '05 #1
6 6146

"David De Cotis" <mc**@mcms.co m> wrote in message
news:26******** *************** *******@ureader .com...
Hello all, I am trying to go through a ListBox and verify if am item was
selected. If an item was selected, I would like to get a handle of the
item

and simply do a response.write on the selected handle. The issue that I
am

facing is that I am going each item, but my code does not catch the
selected

item. Can anyone please take a look at the code and let me know what I am
doing wrong.

If listBox1.Items. Count > 0 Then
For intCount = 0 To listBox1.Items. Count - 1
If listBox1.Select edIndex = True Then
Response.Write( listBox1.Select edIndex)
End If
Next
End If


Um, the listBox1.Select edIndex holds the index of the selected item, so what
are you trying to do?
Nov 19 '05 #2
You don't need to loop through the listbox, just use listBox1.Select edItem,
and by the way, listBox1.Select edIndex isn't a true/false, it's the index
number, starting with 0 of the item selected. So, if the first item was
selected, SelectedIndex would be 0, and if the 8th item was selected,
SelectedIndex would be 7.

"David De Cotis" wrote:
Hello all, I am trying to go through a ListBox and verify if am item was
selected. If an item was selected, I would like to get a handle of the item

and simply do a response.write on the selected handle. The issue that I am

facing is that I am going each item, but my code does not catch the selected

item. Can anyone please take a look at the code and let me know what I am
doing wrong.

If listBox1.Items. Count > 0 Then
For intCount = 0 To listBox1.Items. Count - 1
If listBox1.Select edIndex = True Then
Response.Write( listBox1.Select edIndex)
End If
Next
End If
B.T.W. this is the way the listBox is defined in the .NET HTML page:

<asp:listbox id="listBox1" runat="server" Width="200px"
Height="142px"> </asp:listbox><BR >

Nov 19 '05 #3
David,

If you are trying to catch this information in the selectedindexch anged
event, ensure that the listbox's autopostback feature is enabled. I
was unsure if when you were trying to capture this information, so
simply wanted to put that out there in case that method was being
attempted.

Aaron

Nov 19 '05 #4
Thanks, that is what I thought, but I got sidetracked because when I click
on the button getSelectedItem _Click (see code below) the page seems to
refresh and thereafter the selection that I made on the listbox is not
selected anymore and also the response.write only writes "You have selected
the following item: " and nothing else. It is like when I click on the
button getSelectedItem _Click everything is resetted. Can anyone please give
me an explaination.
Private Sub getSelectedItem _Click(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles getSelectedItem .Click
Response.Write( "You have selected the following item: ")
Response.Write( listBox1.Select edItem)
End Sub
Many thanks to all.
Nov 19 '05 #5
Are you resetting something in the Page_Load method?

"David De Cotis" wrote:
Thanks, that is what I thought, but I got sidetracked because when I click
on the button getSelectedItem _Click (see code below) the page seems to
refresh and thereafter the selection that I made on the listbox is not
selected anymore and also the response.write only writes "You have selected
the following item: " and nothing else. It is like when I click on the
button getSelectedItem _Click everything is resetted. Can anyone please give
me an explaination.
Private Sub getSelectedItem _Click(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles getSelectedItem .Click
Response.Write( "You have selected the following item: ")
Response.Write( listBox1.Select edItem)
End Sub
Many thanks to all.

Nov 19 '05 #6
Thank-you Craig, You hit it right on the mark. In the Page_Load method I
was reading my listbox entries from another posting and thereby creating the
new listbox for the current posting. Obviously, then my selectedindex would
always return nothing. when I place
Response.Write( "You have selected the following item: ")
Response.Write( act_quest_ListB ox.SelectedItem ) In the Page_Load method it
works. My question, how can I call my function from a button without having
my page reloaded????

Thank-you all
Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
22628
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 text of the selected item ? Pete
3
2421
by: Alex Stevens | last post by:
I'd already posted this in microsoft.public.dotnet.framework.windowsforms and microsoft.public.dotnet.framework.windowsforms.controls to no avail so apologies for the cross-posting. Hi, I'm writing a usercontrol which displays the typical two listboxes and the ability to move items from one to the other. The listboxes are populated with my custom objects (SwapItem), which simply
3
3615
by: Paul T. Rong | last post by:
I have a listbox (of product names) control on my form. I want to pass the selected item (a product name) to a subform, and the product unitprice should apear automatically next to the product name in the subform. Is it possible? How do I do this? Thanks in advance. Paul from Slovakia
0
2052
by: bill yeager | last post by:
Duray, it helps in regards to knowing how to get the items that were selected in the lisbox, but I'm going in reverse --- after I get the items from the db that were selected, I'd like to be able to highlight them in the listbox within the datagrid control......... Thanks, Bill... >-----Original Message-----
6
2882
by: Chris Leuty | last post by:
I am populating a multiselect Listbox from a dataset, with the content of the listbox filled by one table, and the selections determined from another table. So far, I have been keeping the dataset a denormalized mirror of the database, but I'm not having much luck getting the selection logic down (I haven't found a 'hook' where I can access the listbox object as an object to set the listitem's selected property before it gets rendered).. ...
1
4953
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 and a forest green border. However, when you move the cursor from one item to the next within the listbox or you click on an item in the listbox to select it, the background turns to the standard windows dark blue with white letters. Well, that...
3
19082
by: Mitch | last post by:
Is the following a correct representation of the relationship of the selected index to selected item: INDEX ITEM 0 "item 1" 1 "item 2" 2 "item 3" and so on. I keep getting the same string for selected index 0 and 1; i.e. both are "item 1". I'm new to C# and not exactly an accomplished programmer. Any suggestions?
9
3249
by: zdrakec | last post by:
Hello all: Clearly, I'm not getting it! Here is the scenario: On a web page, I have two list boxen and a text box. The first listbox is populated at page load time (if it is not a postback). This listbox has AutoPostback = True. When the user selects an item from this list, the second listbox is populated with more items relevant to this selection. I am using an SQLDataSource web control for this. These items are headers. I want, when...
7
5619
by: Lit | last post by:
Hi, How can I capture the vertical scroll bar position for a Listbox. I have a Listbox of 100 items + when I click on it I post back remove the item selected. After returning to the client browser the list box scroll position is at the top.
0
9646
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9483
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10346
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10157
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8982
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7504
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5386
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4055
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.