I have a textbox that I want to make into a search bar. My table has an int "id" and varchar(50) "name". I want to search for either the name or the id in the same textbox. Is that even possible? I've tried many things but haven't gotten to a solution yet.

Here's what I have:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
 ConnectionString="<%$ ConnectionStrings:New_QuickBooksConnectionString %>"      
        SelectCommand="SELECT * FROM [Testing1]" FilterExpression="([id] = {0}) OR ([name] LIKE     '%(CAST {0} AS VARCHAR(50))%')">
<FilterParameters>
 <asp:ControlParameter ControlID="TextBox1" Name="id" PropertyName="Text" Type="int32" />
</FilterParameters>
</asp:SqlDataSource> 

This just returns the id when I type in a number. It doesn't work for name. What can I do?

有帮助吗?

解决方案

Try changing the type = "String" and convert ID to String, like CONVERT([Id],'System.String') like '{0}'

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top