dropdownlist removes whitespace

Discussion in 'Microsoft ASP .NET' started by Guest, Oct 13, 2005.

  1. Guest

    Guest 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
     
    Guest, Oct 13, 2005
    #1
    1. Advertisements

  2. Guest

    Lucas Tam Guest

    "=?Utf-8?B?SmVmZg==?=" <> wrote in
    news::

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

    Newmarket Volvo Sucks! http://newmarketvolvo.tripod.com
     
    Lucas Tam, Oct 13, 2005
    #2
    1. Advertisements

  3. Guest

    Guest Guest

    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
     
    Guest, Oct 13, 2005
    #3
  4. Guest

    Karl Seguin Guest

    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 = "&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" <> wrote in message
    news:Xns96EE7A18FE7BFnntprogerscom@127.0.0.1...
    > "=?Utf-8?B?SmVmZg==?=" <> wrote in
    > news::
    >
    >> 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 ()
    > Please delete "REMOVE" from the e-mail address when replying.
    >
    > Newmarket Volvo Sucks! http://newmarketvolvo.tripod.com
     
    Karl Seguin, Oct 13, 2005
    #4
  5. Guest

    Guest Guest

    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 = " ";
    > }
    > 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" <> wrote in message
    > news:Xns96EE7A18FE7BFnntprogerscom@127.0.0.1...
    > > "=?Utf-8?B?SmVmZg==?=" <> wrote in
    > > news::
    > >
    > >> 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 ()
    > > Please delete "REMOVE" from the e-mail address when replying.
    > >
    > > Newmarket Volvo Sucks! http://newmarketvolvo.tripod.com

    >
    >
    >
     
    Guest, Oct 13, 2005
    #5
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. threecrans

    Remove Whitespace when rendering Server Control

    threecrans, Jul 3, 2003, in forum: Microsoft ASP .NET
    Replies:
    0
    Views:
    512
    threecrans
    Jul 3, 2003
  2. Donal McWeeney

    Div control and additional whitespace

    Donal McWeeney, Oct 17, 2003, in forum: Microsoft ASP .NET
    Replies:
    2
    Views:
    248
    Donal McWeeney
    Oct 20, 2003
  3. mr2_93
    Replies:
    1
    Views:
    636
    mr2_93
    Oct 2, 2005
  4. tshad
    Replies:
    8
    Views:
    449
    tshad
    Oct 19, 2005
  5. Guest
    Replies:
    0
    Views:
    415
    Guest
    Dec 23, 2005
  6. Guest
    Replies:
    0
    Views:
    806
    Guest
    Dec 29, 2005
  7. keithb
    Replies:
    0
    Views:
    841
    keithb
    May 1, 2006
  8. S_K
    Replies:
    5
    Views:
    1,173
    Eliyahu Goldin
    Nov 14, 2007
Loading...