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?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mr2_93
    Replies:
    1
    Views:
    530
    mr2_93
    Oct 2, 2005
  2. tshad
    Replies:
    8
    Views:
    304
    tshad
    Oct 19, 2005
  3. Guest
    Replies:
    0
    Views:
    324
    Guest
    Dec 23, 2005
  4. Guest
    Replies:
    0
    Views:
    666
    Guest
    Dec 29, 2005
  5. keithb
    Replies:
    0
    Views:
    738
    keithb
    May 1, 2006
Loading...

Share This Page