在下拉列表中丢失的空格字符

时间:2013-11-12 07:59:23

标签: html asp.net sql-server-2008 drop-down-menu spaces

我有DropDown List从SQL数据库生成的值

这是我的DropDown列表:

<asp:DropDownList ID="dropProb" AppendDataBoundItems="true" EnableViewState="false"
      runat="server" DataSourceID="Prob" DataTextField="val" DataValueField="Value2">
       <Items>
           <asp:ListItem Text="None" Value=""></asp:ListItem>
        </Items>
</asp:DropDownList>
<asp:SqlDataSource ID="Prob" runat="server" ConnectionString="<%$ConnectionStrings:DispatchConnectionString %>"
SelectCommand="SELECT (rtrim(value2) + space(15 - len(value2)) + Value3) as val,Value2 FROM [Parameter] WHERE ([ParamType] = @ParamType) ">
<SelectParameters>
   <asp:Parameter DefaultValue="PROB" Name="ParamType" Type="String" />
     </SelectParameters>
</asp:SqlDataSource>

我用:

SELECT (rtrim(value2) + space(15 - len(value2)) + Value3) as val,Value2 FROM [Parameter] WHERE ([ParamType] = @ParamType) 

要获取下拉列表中显示的值,根据我的查询,它应该有空格

但不幸的是它没有显示空间,这是图片:

enter image description here

但如果我运行Sql Query,它会给我一个我想要的结果:

enter image description here

我的下拉列表代码有问题吗?或者它无法显示空格字符?

1 个答案:

答案 0 :(得分:1)

您必须将空格替换为&amp; nbps;为了让html正确渲染你的空间

    SELECT REPLACE(
    (rtrim(value2) + space(15 - len(value2)) + Value3),
    ' ',
    '&nbsp;'
    ) as val,
    Value2
    FROM [Parameter]
    WHERE ([ParamType] = @ParamType) 
相关问题