dropdownlist removes whitespace

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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...
 
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.
 
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 &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 = "&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
 
Thanks a lot Karl.... that did it...

Karl Seguin said:
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 = " ";
}
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 said:
Try: Replace(" ", " ", MyItem.text)

See if that works...



--
Lucas Tam ([email protected])
Please delete "REMOVE" from the e-mail address when replying.

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top