I have a gridview bound to a LINQ to Sql datasource. I would like to filter the the results in the gridview using the LIKE operator. i.e I have a textbox used to Search on Username and I would like to select all users with the username like [textbox value].
Below is my code:
<h1>Manage Users</h1>
Search for users
Username:
<asp:GridView ID="GridView2" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" DataSourceID="LinqDataSource1">
<Columns>
<asp:BoundField DataField="UserName" HeaderText="User Name" ReadOnly="True"
SortExpression="UserName" />
<asp:BoundField DataField="FullName" HeaderText="Full Name" ReadOnly="True"
SortExpression="FullName" />
<asp:BoundField DataField="Email" HeaderText="Email" ReadOnly="True"
SortExpression="Email" />
<asp:BoundField DataField="LastLoginDate" HeaderText="Last Login" ReadOnly="True"
SortExpression="LastLoginDate" DataFormatString="{0:dd MMMM yyyy}"/>
<asp:HyperLinkField Text="Edit" DataNavigateUrlFields="UserId" DataNavigateUrlFormatString="~/Pages/UsersMaintenance/CreateEditUser.aspx?UserId={0}" />
</Columns>
</asp:GridView>
<asp:LinqDataSource ID="LinqDataSource1" runat="server"
ContextTypeName="AirProducts.BusinessLogic.AirProductsDataContext"
Select="new (UserId,UserName, Details.FullName,Membership.Email,Membership.LastLoginDate)"
TableName="Users" Where="UserName == @UserName" >
<WhereParameters>
<asp:ControlParameter ControlID="txtUsername" Name="UserName"
PropertyName="Text" Type="String" />
</WhereParameters>
</asp:LinqDataSource>