473,466 Members | 3,167 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Listbox with spaces from SQL query

I am trying to populate a listbox with data that is pulled from a sql
query. Here is my C# code behind the page:
sqlConn1.Open();
SqlCommand sqlComm2 = new SqlCommand("SElECT
replace((mc.MAINTENT.id + space(20-len(mc.maintent.id))+
left(mc.MAINTENT.aenm,50) +
space(50-len(left(mc.maintent.aenm,50)))+mc.mtntype.id),' ','&nbsp') as
Description, mc.maintent.mtnoi FROM mc.MAINTENT INNER JOIN mc.MTNTYPE
ON mc.MAINTENT.mtctyp_oi = mc.MTNTYPE.mtoi WHERE (mc.MAINTENT.id >=
'F92') AND (mc.MAINTENT.aenm LIKE '%%') AND (mc.MTNTYPE.id LIKE '%%')
ORDER BY mc.MAINTENT.id", sqlConn1);
SqlDataReader sqlRead2 = sqlComm2.ExecuteReader();
lbEntities.DataSource = sqlRead2;
lbEntities.DataTextField = "Description";
lbEntities.DataValueField = "mtnoi";
lbEntities.DataBind();
sqlConn1.Close();

As you can see, I want to have white spaces in my listbox so the
columns appear nicely. I am replacing the spaces with &nbsp in my
query. The problem is that when the listbox displays, rather than
spaces I get    etc. How do I pass the &nbsp from the query
to display the correct spaces in my listbox?

Dec 15 '06 #1
2 2909
Listboxes are converted into MFC droplist controls in Internet
Explorer; they do not display HTML code themselves.

The best you can do is apply a class in a Cascading Style Sheet (or set
the style attribute on the listbox) to have the text in the box render
in a fixed pitch font. You can then use regular spaces to align its
entries.

Dec 15 '06 #2
da********@gmail.com wrote:
I am trying to populate a listbox with data that is pulled from a sql
query. Here is my C# code behind the page:
....
As you can see, I want to have white spaces in my listbox so the
columns appear nicely. I am replacing the spaces with &nbsp in my
query. The problem is that when the listbox displays, rather than
spaces I get    etc. How do I pass the &nbsp from the query
to display the correct spaces in my listbox?
You'll need to use a fixed size font (Courier New for example) in your
listbox. Then replace the spaces in your listitems with an HTML entity
that will actually render as spaces in the listbox (not so easy, as you
may have found). Here's how to get the entity:

System.IO.StringWriter sWriter = new System.IO.StringWriter();
//get the HTML space ready.
HttpContext.Current.Server.HtmlDecode(" ", sWriter);
string sHTMLSpace = sWriter.ToString();

Then you need to replace all the spaces that you just pulled back from
the server with sHTMLSpace. I believe ASP.NET will let you do
something like this after databinding:

foreach (ListItem li in lbEntities.Items)
{
li.Text = li.Text.Replace(" ", sHTMLSpace);
}

Anyway, that should set you on the right path.

Matt

Dec 18 '06 #3

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

Similar topics

17
by: amber | last post by:
Hello. Can someone tell me what I may be doing wrong here? I'm using the code (lboxRP is a listbox): Dim newRPindex As Integer newRPindex = Me.lboxRP.FindString(RP)...
2
by: Simon P | last post by:
Hello group, I'm in desperate need of help. Here goes : I have the following tables : CONTACTS (ContactID, FirstName, LastName, Company, etc.), SHOWS (ShowID, ShowDescription) and SHOWDETAILS...
2
by: Geir Baardsen | last post by:
Hi! From a listbox I'd like to send only selected items to a report. Items will include: OrderNr,Date,EmployeeNr from tblOrders ZipCode,City from tblZipCodes Name,Adr,ZipID from...
4
by: carl.barrett | last post by:
Hi, I have a list box that displays 2 columns. Behind it sits a query with five columns. These are Column1 (DOB), column2 (a concatenated string of Surname Forname, Title), Column3 (Surname),...
6
by: Manan | last post by:
hello All, I have a simple question..I'm creating a tempString that contains my values then i'm adding to a ListItemCollection (). In my tempString i'm adding a spaces between each values it...
1
by: Do | last post by:
Hi, When I add some spaces to a listbox control using   they seem to appear in the listbox when the page loads. Do I have to do some converstion to get spaces in a listbox? Do
4
by: Mike Parris | last post by:
I want to represent a list of items as a heirarchy by, indenting each item by a set amount depending on its level. For example level 1 = no spaces, level 1 = 2 spaces etc. If I try too use...
6
by: Paul | last post by:
Hi All, Framework 1.1 listbox control unable to DataBind I've been googling for an answer to this query that appears quite a lot, but none, it seem, answers my problem directly. I am...
1
by: MaRkHaSBEEnMade | last post by:
Hi there I currently have a listbox that displays provinces,regions and suburbs.I want to pad the items logically with spaces,but the spaces are being igonred... eg Province1 ...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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: 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?

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.