473,473 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

ListBox question

Rob
I have a listbox which is populated by a dataset:
'initiate the DataSet and all the rest here

my sql statement is this:
SELECT company_id, name, description FROM companies

ds = DataControl.GetDataSet(sql)
lstCompanies.DataSource = ds
lstCompanies.DataTextField = "name"
lstCompanies.DataValueField = "company_id"
lstCompanies.DataBind()

When I click on a listItem, I want to be able to show the description
(which is in the DataSet) of that company on a label beside the listbox.
Is there anyway of doing this? The listbox doesn't even have a Click
event.

Thanks

Rob


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #1
2 1572
> I have a listbox which is populated by a dataset:
'initiate the DataSet and all the rest here
my sql statement is this:
SELECT company_id, name, description FROM companies
ds = DataControl.GetDataSet(sql)
lstCompanies.DataSource = ds
lstCompanies.DataTextField = "name"
lstCompanies.DataValueField = "company_id"
lstCompanies.DataBind()
When I click on a listItem, I want to be able to show the description
(which is in the DataSet) of that company on a label beside the
listbox. Is there anyway of doing this? The listbox doesn't even have
a Click event.


What I've done in the past is pass down an array of id and description values
then added a handler for the onchange of the <select> element (should be
what the listbox renders as so you could likely add an attribute to the listbox
for the onchange) call a method to update the label (or in my case a textbox).
The rendered output should look something like so:

<!-- Output this using a Page.RegisterClientScriptBlock call) after you bind
-->
<script type="text/javascript">var listboxId_values = [[id1,desc1],[id2,desc2]];</script>

<!-- This should resemble the output of the ListBox control with an onchange
attribute added -->
<select id="listboxId" onchange="updateRelated('listboxId', 'labelId', listboxId_values);">
...
</select>

<!-- This should resemble the output of a Label -->
<span id="labelId"></span>

<!-- throw this anywhere it will be included on the page -->
<script type="text/javascript">
function updateRelated(sid, rid, values)
{
// select element
var s = document.getElementById(sid);
// target
var r = document.getElementById(rid);

var v = s.value;
var i = 0;

while(i < values.length && values[i][0] != v)
i++;

if(i < values.length)
{
r.innerText = values[i][1];
}
}
</script>

hth, Ryan
Nov 19 '05 #2
Rob
Thanks Ryan,
I can't seem to call Page.RegisterClientScriptBlock. It's not available
as an option. Do I need to Import something?

I'm new to .Net

Rob

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #3

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

Similar topics

4
by: f_salazar | last post by:
English Version !! Hi !! I have a page with a Form, inside the form I have listbox with 'X' elements. Wend I submit the page, an ASP process inside the page have to read those elements and...
3
by: Stimp | last post by:
I have a listbox of values that I populate from a database. I want the user to be able to re-order the list (by first selecting an item and then clicking 'up' or 'down' buttons) and then save...
8
by: Steve Schroeder | last post by:
For some reason I cannot get the OnSelectedIndexChanged event to fire for a listbox I have on a page. I'm able to populate the listbox with data from a stored procedure, but cannot trigger the...
21
by: Bilal Abbasi | last post by:
I realize that you can add items to a list box as objects so you can have access to more than just one property like the itemindex in vb6. Question I have is how do I cause the listbox to show a...
3
by: George | last post by:
Sub ExcelToListBox() Dim xRange As Object Dim ary Dim xValue As String xRange = oXL.Range("A1:A9") 'has letters A-H ary = xRange.value xValue = ary(3, 1) 'xValue = C...
0
by: | last post by:
Greets All, Question on data in datagrid /listbox and looping? I’m trying to decide the best way to write this code. 1 would like the user to make several selections from one listbox/combo box...
0
by: | last post by:
Greets All, Question on data in datagrid /listbox and looping? I’m trying to decide the best way to write this code. 1 would like the user to make several selections from one listbox/combo box...
2
by: dan NY | last post by:
I'm a struggling new VB Applications user that has what may be a simple question, but I've been struggling with it. I'm using a response to a message box YesNo question to cause one of two...
3
by: caracolito1975 | last post by:
Hi to every one!!!! For some time now I'm programing in .NET and I have a question in using ListBox I need to databind a collection to a ListBox. My code is something like this: using...
8
by: jh | last post by:
I'd like to copy/paste into a listbox during runtime. I can do this for a textbox but can't figure out how to accomplish this for a listbox. Any help? Thanks.
0
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,...
0
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...
0
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,...
0
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...
1
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
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
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.