PC Review


Reply
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average.

dropdownlist removes whitespace

 
 
=?Utf-8?B?SmVmZg==?=
Guest
Posts: n/a
 
      13th Oct 2005
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
 
Reply With Quote
 
 
 
 
Lucas Tam
Guest
Posts: n/a
 
      13th Oct 2005
"=?Utf-8?B?SmVmZg==?=" <(E-Mail Removed)> wrote in
news:(E-Mail Removed):

> 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 ((E-Mail Removed))
Please delete "REMOVE" from the e-mail address when replying.

Newmarket Volvo Sucks! http://newmarketvolvo.tripod.com
 
Reply With Quote
 
 
 
 
=?Utf-8?B?Q3VydF9DIFtNVlBd?=
Guest
Posts: n/a
 
      13th Oct 2005
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

 
Reply With Quote
 
Karl Seguin
Guest
Posts: n/a
 
      13th Oct 2005
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" <(E-Mail Removed)> wrote in message
news:Xns96EE7A18FE7BFnntprogerscom@127.0.0.1...
> "=?Utf-8?B?SmVmZg==?=" <(E-Mail Removed)> wrote in
> news:(E-Mail Removed):
>
>> 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 ((E-Mail Removed))
> Please delete "REMOVE" from the e-mail address when replying.
>
> Newmarket Volvo Sucks! http://newmarketvolvo.tripod.com



 
Reply With Quote
 
=?Utf-8?B?SmVmZg==?=
Guest
Posts: n/a
 
      13th Oct 2005
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" <(E-Mail Removed)> wrote in message
> news:Xns96EE7A18FE7BFnntprogerscom@127.0.0.1...
> > "=?Utf-8?B?SmVmZg==?=" <(E-Mail Removed)> wrote in
> > news:(E-Mail Removed):
> >
> >> 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 ((E-Mail Removed))
> > Please delete "REMOVE" from the e-mail address when replying.
> >
> > Newmarket Volvo Sucks! http://newmarketvolvo.tripod.com

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView: Filtr DropDownList from another DropDownList =?Utf-8?B?SnVhbmpv?= Microsoft ASP .NET 0 23rd Dec 2005 02:31 PM
MODI layout object, text property (removes whitespace) =?Utf-8?B?VG9kZCBTaGVhcmVy?= Microsoft Access VBA Modules 0 9th Dec 2005 11:20 PM
databinding a Dropdownlist to another dropdownlist tshad Microsoft ASP .NET 8 19th Oct 2005 11:00 PM
Using a data-bind dropdownlist to populate another data-bind dropdownlist mr2_93 Microsoft ASP .NET 1 2nd Oct 2005 06:07 PM
DropDownList depending on DropDownList Jonathan Microsoft Dot NET 1 1st Nov 2004 04:51 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:23 AM.