By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,849 Members | 2,169 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,849 IT Pros & Developers. It's quick & easy.

dropdownlist removes whitespace

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
"=?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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.