filter a SqlDataSource


Joined
Mar 26, 2010
Messages
2
Reaction score
0
Hi,

I am trying to filter a SqlDataSource based on two fields (textboxes). Currently both textboxes have to be filled in to get any results, is there a way where only one text could be filled in like either the first name or the last name, and still get results.

Any help is MUCH appreciated. Thanks!

my current code is this:

<form id="form1" runat="server">
<div>

</div>
<br />
<asp:TextBox ID="contractID" runat="server">contractID</asp:TextBox>
<asp:TextBox ID="duration" runat="server">duration</asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" />
<br />
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1">
</asp:GridView>
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT DISTINCT * FROM [Contract]" FilterExpression="contractID LIKE '{0}%' AND duration LIKE '{1}%'">
<FilterParameters>
<asp:ControlParameter ControlID="contractID" Name="contractID"
PropertyName="Text" Type="String" />
<asp:ControlParameter ControlID="duration" Name="duration" PropertyName="Text"
Type="String" />
</FilterParameters>
</asp:SqlDataSource>

<br />
<br />
</form>
</body>
</html>
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top