Question

I Have DropDown List which the value generated from SQL Database

here's my DropDown List :

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

I use :

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

to get the value to displayed on the drop downlist, it should have space according my query,

but unfortunately it didn't show the space, here's the picture :

enter image description here

but if I run the Sql Query it's give me the result what I want :

enter image description here

is it something wrong with my dropdownlist code? or it couldn't show the space character?

Était-ce utile?

La solution

you must replace empty spaces to &nbps; in order for html to render your spaces correctly

    SELECT REPLACE(
    (rtrim(value2) + space(15 - len(value2)) + Value3),
    ' ',
    '&nbsp;'
    ) as val,
    Value2
    FROM [Parameter]
    WHERE ([ParamType] = @ParamType) 
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top