0
我有Gridview
使用這種SqlDataSource
爲DataSource
SQL Server和ASP.NET:在SqlDataSource的(FilterExpression)過濾 「位」 數據類型使用的DropDownList
<asp:SqlDataSource ID="dsMetal" runat="server"
ConnectionString="<%$ConnectionStrings:connStr%>"
SelectCommand="select MetalName, MetalID, IsAvailable from Metal Where IsDeleted = 0" FilterExpression="IsAvailable like '%{0}%'>
<asp:ControlParameter Name="IsAvailable" ControlID="ddlIsMetalAvailable" PropertyName="SelectedValue" Type="Boolean" />
</asp:SqlDataSource>
,這是我的DropDownList:
<asp:DropDownList ID="ddlIsMetalAvailable" DataValueField="IsAvailable"
AppendDataBoundItems="true" AutoPostBack="true" runat="server" Width="150">
<asp:ListItem Text="True" Value="True" />
<asp:ListItem Text="False" Value="False" />
</asp:DropDownList>
我得到一個錯誤:
Cannot perform 'Like' operation on System.Boolean and System.String.
我有也試過這種過濾器表達,但它並沒有幫助我:
FilterExpression="Convert(IsAvailable, 'System.Boolean') like '%{0}%'
IsAvailable是Bool字段嗎? –
它是一個SQL SERVER的BIT數據類型 – Pritesh
那麼你不應該在where條件下使用Like操作符 –