<asp:ListItem> in v2

Discussion in 'ASP .Net' started by Mark Rae, Jan 27, 2006.

  1. Mark Rae

    Mark Rae Guest

    Hi,

    Has the <asp:DropDownList> - <asp:ListItem> functionality changed in v2? In
    v1.1, the following works as expected:

    <asp:DropDownList ID="cmbStatus" Runat=server EnableViewState=False>
    <asp:ListItem Value=0>&nbsp;</asp:ListItem>
    <asp:ListItem Value=1>Awaiting</asp:ListItem>
    <asp:ListItem Value=2>Current</asp:ListItem>
    <asp:ListItem Value=3>Terminated</asp:ListItem>
    </asp:DropDownList>

    i.e. three options with a blank option at the top.

    However, in v2, the first option (i.e. the one which should be blank)
    displays with a zero instead of the non-breaking space - when I do a View
    Source, I can see that &nbsp; has been replaced by 0.

    Is this normal?

    Mark
     
    Mark Rae, Jan 27, 2006
    #1
    1. Advertising

  2. Mark,

    Spaces get trimmed off of drop down lists autmatically. So the list must
    think it's completely empty and then substitutes the value.

    Yes, I think this is by design. There is a way to encode a space so it shows
    up in a drop down list. I have a StringUtilities object that I give away on
    my website and one of the routines in it is a way to pad encode spaces so
    that a drop down list may be padded.

    Here's the routine:

    Private Function Pad(ByVal server As HttpServerUtility, ByVal numberOfSpaces
    As Int32) As String
    Try
    Dim Spaces As String
    For items As Int32 = 1 To numberOfSpaces
    Spaces &= "&nbsp;"
    Next
    Return server.HtmlDecode(Spaces)
    Catch ex As Exception
    Throw ex
    End Try

    --
    Sincerely,

    S. Justin Gengo, MCP
    Web Developer / Programmer

    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzsche
    "Mark Rae" <> wrote in message
    news:...
    > Hi,
    >
    > Has the <asp:DropDownList> - <asp:ListItem> functionality changed in v2?
    > In v1.1, the following works as expected:
    >
    > <asp:DropDownList ID="cmbStatus" Runat=server EnableViewState=False>
    > <asp:ListItem Value=0>&nbsp;</asp:ListItem>
    > <asp:ListItem Value=1>Awaiting</asp:ListItem>
    > <asp:ListItem Value=2>Current</asp:ListItem>
    > <asp:ListItem Value=3>Terminated</asp:ListItem>
    > </asp:DropDownList>
    >
    > i.e. three options with a blank option at the top.
    >
    > However, in v2, the first option (i.e. the one which should be blank)
    > displays with a zero instead of the non-breaking space - when I do a View
    > Source, I can see that &nbsp; has been replaced by 0.
    >
    > Is this normal?
    >
    > Mark
    >
     
    S. Justin Gengo [MCP], Jan 27, 2006
    #2
    1. Advertising

  3. Mark Rae

    Mark Rae Guest

    "S. Justin Gengo [MCP]" <justin@[no_spam_please]aboutfortunate.com> wrote in
    message news:...

    > Spaces get trimmed off of drop down lists autmatically.


    Since when? They certainly didn't in v1.x

    > So the list must think it's completely empty and then substitutes the
    > value.


    That makes no sense to me...

    > Yes, I think this is by design.


    How intensely irritating.

    > There is a way to encode a space so it shows up in a drop down list.


    Yeah, one line of code will do that...
    <DropDownList>.Items.Insert(0, new ListItem("", "0"));

    That's not what I'm talking about - I'm talking about creating the
    DropDownList and its ListItems in the source, not the code behind...
     
    Mark Rae, Jan 27, 2006
    #3
  4. Mark,

    In that case, did you fail to try the obvious?

    <asp:DropDownList ID="Test" runat="server">

    <asp:ListItem Value="0" Text=""></asp:ListItem>

    <asp:ListItem Value="1" Text="One"></asp:ListItem>

    </asp:DropDownList>



    Works just fine.


    --
    Sincerely,

    S. Justin Gengo, MCP
    Web Developer / Programmer

    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzsche
    "Mark Rae" <> wrote in message
    news:...
    > "S. Justin Gengo [MCP]" <justin@[no_spam_please]aboutfortunate.com> wrote
    > in message news:...
    >
    >> Spaces get trimmed off of drop down lists autmatically.

    >
    > Since when? They certainly didn't in v1.x
    >
    >> So the list must think it's completely empty and then substitutes the
    >> value.

    >
    > That makes no sense to me...
    >
    >> Yes, I think this is by design.

    >
    > How intensely irritating.
    >
    >> There is a way to encode a space so it shows up in a drop down list.

    >
    > Yeah, one line of code will do that...
    > <DropDownList>.Items.Insert(0, new ListItem("", "0"));
    >
    > That's not what I'm talking about - I'm talking about creating the
    > DropDownList and its ListItems in the source, not the code behind...
    >
     
    S. Justin Gengo [MCP], Jan 27, 2006
    #4
  5. Mark Rae

    Mark Rae Guest

    "S. Justin Gengo [MCP]" <justin@[no_spam_please]aboutfortunate.com> wrote in
    message news:...

    > Works just fine.


    Not for me - still replaces the empty string with the zero...
     
    Mark Rae, Jan 27, 2006
    #5
  6. Then something is wrong with your install.

    Did you take a close look at the code? I'm setting the text parameter of the
    list item instead of putting the text between the list item tags.

    I've tested it on three machines each running visual studio 2005 and tested
    placing it out on a test website and it works on all.

    --
    Sincerely,

    S. Justin Gengo, MCP
    Web Developer / Programmer

    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzsche
    "Mark Rae" <> wrote in message
    news:%...
    > "S. Justin Gengo [MCP]" <justin@[no_spam_please]aboutfortunate.com> wrote
    > in message news:...
    >
    >> Works just fine.

    >
    > Not for me - still replaces the empty string with the zero...
    >
     
    S. Justin Gengo [MCP], Jan 27, 2006
    #6
    1. Advertising

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. CGuy

    A question about <asp:ListItem>

    CGuy, Sep 29, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    421
  2. Mad Scientist Jr
    Replies:
    2
    Views:
    495
    Mad Scientist Jr
    Jun 29, 2004
  3. =?Utf-8?B?U2lsZWVzaA==?=

    Urgent!!!!!!!! Adding Items to <Asp:ListItem> thru Javascript

    =?Utf-8?B?U2lsZWVzaA==?=, Nov 4, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,092
    Curt_C [MVP]
    Nov 4, 2004
  4. Harold
    Replies:
    4
    Views:
    3,873
    Harold
    Dec 8, 2004
  5. Jim in Arizona
    Replies:
    7
    Views:
    973
    Badass Scotsman
    Nov 22, 2006
Loading...

Share This Page