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("SEl ECT
replace((mc.MAI NTENT.id + space(20-len(mc.maintent .id))+
left(mc.MAINTEN T.aenm,50) +
space(50-len(left(mc.mai ntent.aenm,50)) )+mc.mtntype.id ),' ',' ') as
Description, mc.maintent.mtn oi FROM mc.MAINTENT INNER JOIN mc.MTNTYPE
ON mc.MAINTENT.mtc typ_oi = mc.MTNTYPE.mtoi WHERE (mc.MAINTENT.id >=
'F92') AND (mc.MAINTENT.ae nm LIKE '%%') AND (mc.MTNTYPE.id LIKE '%%')
ORDER BY mc.MAINTENT.id" , sqlConn1);
SqlDataReader sqlRead2 = sqlComm2.Execut eReader();
lbEntities.Data Source = sqlRead2;
lbEntities.Data TextField = "Descriptio n";
lbEntities.Data ValueField = "mtnoi";
lbEntities.Data Bind();
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   in my
query. The problem is that when the listbox displays, rather than
spaces I get etc. How do I pass the   from the query
to display the correct spaces in my listbox? 2 2926
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. da********@gmai l.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   in my
query. The problem is that when the listbox displays, rather than
spaces I get etc. How do I pass the   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.Strin gWriter sWriter = new System.IO.Strin gWriter();
//get the HTML space ready.
HttpContext.Cur rent.Server.Htm lDecode(" ", sWriter);
string sHTMLSpace = sWriter.ToStrin g();
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.Item s)
{
li.Text = li.Text.Replace (" ", sHTMLSpace);
}
Anyway, that should set you on the right path.
Matt This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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)
Me.lboxRP.SetSelected(newRPindex, True)
When the last line executes, I get an error message:
|
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 (links the previous tables together so not to have a
many-to-many relationship -- has the ContactID and ShowID fields).
I have a main form with a couple of listboxes which are used for
querying the CONTACTS table. The results populate bound fields...
|
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 tblCustomers
OrderNr,ItemID,Amount,Price,Discount from tblOrderDetails
|
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), column4 (Forename) and
column5 (title). Columns 3,4 and 5 are not shown in the list box only
the first two.
DOB Name: &" "&&", "&
|
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 works fine..when I add to a ListBox the HTML
doesn't render the spaces..Anyhelp is appreciated...
Tanks
Manan
| |
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
|
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 leading spaces or tabs to do this the
control removes them. Is there a way to do this?
Mike
|
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 populating a listbox with an array of very simple "Country" objects via
a WebService. The Country class contains CountryID,TLDs and Name properties
each of which have a getter and setter (I found that properties without
|
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
Regions1
region2
Province2
Region3
|
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...
|
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...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |