I have Gridview which uses this SqlDataSource as DataSource
<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>
And this is my 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>
I am getting an error:
Cannot perform ‘Like’ operation on System.Boolean and System.String.
I have also tried this filter expression but it doesn’t helps me:
FilterExpression="Convert(IsAvailable, 'System.Boolean') like '%{0}%'
Just read the error message – it clearly says what’s wrong:
You cannot use
LIKEwith a boolean value – you need to use an exact match.So change your markup to be:
With this change, things should work just fine.