Home All Groups Group Topic Archive Search About

White spaces in DropDownList / Listbox / ...

Author
16 Nov 2005 1:20 PM
Frederic H
Hi all,

I want to add white spaces to format a DropDownList or another web control
but
when the control is rendered ASP.NET convert my " " to " "
Without using   to format the string, I cannot create create a combo like
this

USER1                     | Alan Smith                | 25/01/1981
USER2                     | Brian Smith               | 12/06/1983
.....

I can create a custom web control but I have to use ASP.NET native web
controls.

Author
16 Nov 2005 6:13 PM
vMike
Show quote Hide quote
"Frederic H" <Freder***@discussions.microsoft.com> wrote in message
news:3A2F8D49-D408-4727-8144-ACC552B2C3F8@microsoft.com...
> Hi all,
>
> I want to add white spaces to format a DropDownList or another web control
> but
> when the control is rendered ASP.NET convert my " " to "&nbsp;"
> Without using   to format the string, I cannot create create a combo like
> this
>
> USER1                     | Alan Smith                | 25/01/1981
> USER2                     | Brian Smith               | 12/06/1983
> ....
>
> I can create a custom web control but I have to use ASP.NET native web
> controls.

Here is an example that was posted some time ago by someone else.

<%@ Page Language="VB" Debug="true" %>
<script language=VB runat=server>

Sub Page_Load(Sender As Object, E As EventArgs)

    Dim Padding As String
    Dim writer As New System.IO.StringWriter()
    Dim DecodedString As String

    Padding = "&nbsp;&nbsp;"
    Server.HtmlDecode(Padding, writer)
    Padding = writer.ToString()

    myDropDownList2.Items.Add(Padding & " MVP's")

    Padding = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
    Server.HtmlDecode(Padding, writer)
    Padding = writer.ToString()

    myDropDownList2.Items.Add(Padding & " MVP's")

    myDropDownList2.Items.Add("MVP's" & Padding & "Do Their best")

End Sub

</script>
<html>
<head><title>Padding DropListBox</title></head>
<body><form fred runat="server"><asp:dropdownlist id="MyDropDownList2"
runat="server"/></form></body>
</html>


mike
Author
17 Nov 2005 8:18 AM
Frederic H
Thank you for this help!

(Server.HtmlDecode works only on ASP.NET : if you want to use it in
another project (class library for example)  use the System.Web.HttpUtility
Class)

Example :
Dim writer As New System.IO.StringWriter
Dim HttpUtils As New System.Web.HttpUtility
HttpUtils.HtmlDecode(myRow("Description"), writer)
myRow("Description") = writer.ToString
writer.Close()