473,387 Members | 3,750 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,387 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 1568
> 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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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,...

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.