473,320 Members | 2,189 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,320 software developers and data experts.

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 1564
> 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
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.