473,320 Members | 1,865 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.

dropdownlist removes whitespace

Help....

I have formatted a lsit of strings to add to a dropdownlist to shows three
colums: id, description and price.
i.e.
123 description here $12.95
12456 another description $123.01

But when the text is rendered the white space is removed so it looks like
this:
123 descripion here $12.95
12456 another description $123.01

It's a long list and I would like the values to line up. Is there a way to
keep the control from removing the white space?

I tried a list box and it does the same thing.
Is there another control that would do the job?

Thanks again for any help
Jeff
Nov 19 '05 #1
4 3746
"=?Utf-8?B?SmVmZg==?=" <Je**@discussions.microsoft.com> wrote in
news:BC**********************************@microsof t.com:
Help....

I have formatted a lsit of strings to add to a dropdownlist to shows
three colums: id, description and price.
i.e.
123 description here $12.95
12456 another description $123.01

But when the text is rendered the white space is removed so it looks
like this:
123 descripion here $12.95
12456 another description $123.01

It's a long list and I would like the values to line up. Is there a
way to keep the control from removing the white space?

I tried a list box and it does the same thing.
Is there another control that would do the job?

Try: Replace(" ", "&nbsp", MyItem.text)

See if that works...

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.

Newmarket Volvo Sucks! http://newmarketvolvo.tripod.com
Nov 19 '05 #2
This is by design. It happens in all html.
You MAY be able to replace the " " with " " and fool it but most likely you
will need a Multi-Column Dropdown. Check on www.asp.net in the controls
gallery, there may be one or two.

--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com

"Jeff" wrote:
Help....

I have formatted a lsit of strings to add to a dropdownlist to shows three
colums: id, description and price.
i.e.
123 description here $12.95
12456 another description $123.01

But when the text is rendered the white space is removed so it looks like
this:
123 descripion here $12.95
12456 another description $123.01

It's a long list and I would like the values to line up. Is there a way to
keep the control from removing the white space?

I tried a list box and it does the same thing.
Is there another control that would do the job?

Thanks again for any help
Jeff

Nov 19 '05 #3
I'm pretty sure the &nbsp; will get encoded by asp.net and turn into the
literam &amp;nbsp;

so you'd end up with

Canada
&amp;nbsp;&amp;nbsp;Ontario
&amp;nbsp;&amp;nbsp;Quebect
You need HtmlDecode the &nbsp. I like to use a utility function:

private void Page_Load(object sender, EventArgs e)
{
ddl.Items.Add("Canada");
ddl.Items.Add(Padding(2) + "Ontario");
ddl.Items.Add(Padding(2) + "Quebec");
ddl.Items.Add(Padding(2) + "PEI");
}

public static string Padding(int count)
{
if (count == 0)
{
return string.Empty;
}
string[] s = new string[count];
for (int i = 0; i < count; ++i)
{
s[i] = "&nbsp;";
}
return HttpUtility.HtmlDecode(string.Join("", s));
}
Or, even better, create a custom server control which you can easily use
like a normal dropdownlist:

public class PaddedDropDownList : DropDownList
{
protected override void Render(HtmlTextWriter writer)
{
foreach (ListItem item in Items)
{
item.Text = item.Text.Replace(" ",
HttpUtility.HtmlDecode("&nbsp;"));
}
base.Render(writer);
}
}
Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Lucas Tam" <RE********@rogers.com> wrote in message
news:Xn***************************@127.0.0.1...
"=?Utf-8?B?SmVmZg==?=" <Je**@discussions.microsoft.com> wrote in
news:BC**********************************@microsof t.com:
Help....

I have formatted a lsit of strings to add to a dropdownlist to shows
three colums: id, description and price.
i.e.
123 description here $12.95
12456 another description $123.01

But when the text is rendered the white space is removed so it looks
like this:
123 descripion here $12.95
12456 another description $123.01

It's a long list and I would like the values to line up. Is there a
way to keep the control from removing the white space?

I tried a list box and it does the same thing.
Is there another control that would do the job?

Try: Replace(" ", "&nbsp", MyItem.text)

See if that works...

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.

Newmarket Volvo Sucks! http://newmarketvolvo.tripod.com

Nov 19 '05 #4
Thanks a lot Karl.... that did it...

"Karl Seguin" wrote:
I'm pretty sure the will get encoded by asp.net and turn into the
literam

so you'd end up with

Canada
Ontario
Quebect
You need HtmlDecode the . I like to use a utility function:

private void Page_Load(object sender, EventArgs e)
{
ddl.Items.Add("Canada");
ddl.Items.Add(Padding(2) + "Ontario");
ddl.Items.Add(Padding(2) + "Quebec");
ddl.Items.Add(Padding(2) + "PEI");
}

public static string Padding(int count)
{
if (count == 0)
{
return string.Empty;
}
string[] s = new string[count];
for (int i = 0; i < count; ++i)
{
s[i] = " ";
}
return HttpUtility.HtmlDecode(string.Join("", s));
}
Or, even better, create a custom server control which you can easily use
like a normal dropdownlist:

public class PaddedDropDownList : DropDownList
{
protected override void Render(HtmlTextWriter writer)
{
foreach (ListItem item in Items)
{
item.Text = item.Text.Replace(" ",
HttpUtility.HtmlDecode(" "));
}
base.Render(writer);
}
}
Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Lucas Tam" <RE********@rogers.com> wrote in message
news:Xn***************************@127.0.0.1...
"=?Utf-8?B?SmVmZg==?=" <Je**@discussions.microsoft.com> wrote in
news:BC**********************************@microsof t.com:
Help....

I have formatted a lsit of strings to add to a dropdownlist to shows
three colums: id, description and price.
i.e.
123 description here $12.95
12456 another description $123.01

But when the text is rendered the white space is removed so it looks
like this:
123 descripion here $12.95
12456 another description $123.01

It's a long list and I would like the values to line up. Is there a
way to keep the control from removing the white space?

I tried a list box and it does the same thing.
Is there another control that would do the job?

Try: Replace(" ", " ", MyItem.text)

See if that works...

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.

Newmarket Volvo Sucks! http://newmarketvolvo.tripod.com


Nov 19 '05 #5

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

Similar topics

2
by: Wolfgang Jeltsch | last post by:
Hello, it is often convenient to insert whitespace into an XML document in order to format it nicely. For example, take this snippet of a notional DocBook XML document: <para> This is a...
18
by: Julia Hu | last post by:
Hi, I have a datagrid, and in different rows I need to programmatically bind different type of controls and load data into these controls. For example,in the first row I need to bind data into a...
2
by: Rui Macdonald | last post by:
What is wrong with this code to populate a DropDownList? Can somebody Help me? Tnx RMac ===================================================================================== WebForm.aspx.vb
3
by: Aaron Sellers | last post by:
Hi all, I have a nicely formatted .xml file that loses that nice formatting when I edit it and use XmlDocument.Save to save the file. Does anyone know of any way to keep the formatting I had when...
2
by: Przemek | last post by:
Hi, I've populated my dropdown list from database (category table) via datatable. It's showing categories in strings. The problem appears, when I want to add new record to database...
1
by: Tor Inge Rislaa | last post by:
DataList removes the linefeed When entering the text below in a field in my database with data type TEXT it is displayed as below, line by line. Line1 Line2
0
by: mharness | last post by:
Hello, Under most circumstances I don't have any trouble removing items from a dropdownlist but this time it's not working. I have a ddl that list items which, when choosen are added to a...
6
by: Bill Gower | last post by:
I have a asp.net page that has a DDL tied to a ObjectDataSource. I want the DDL to display a blank in the list when the page is first displayed and let the user select the entry they want. I have...
0
by: Jason | last post by:
The following code removes a particular item from my drop down. Instead, I would like to replace it's value with another string. How can I do that in vb.net? Dim ddl =...
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...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
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....

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.