I have a gridview with columns: id
, name
, address
, phone
And a TextBox: NameFilter
My gridview is populated by a SqlDataSource controller.
I need to filter my gridview registers with name
.
I'm trying with 'FilterParameters' but I don't know why this does not work.
NameFilter
<asp:TextBox ID="NameFilter" runat="server" Text="1"></asp:TextBox>
SqlDataSource
<asp:TextBox ID="NameFilter" runat="server"></asp:TextBox>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:okadConnectionString %>"
ProviderName="<%$ ConnectionStrings:okadConnectionString.ProviderName %>"
SelectCommand="SELECT * FROM factory">
</asp:SqlDataSource>
By using the FilterParameters
you just create the SQL parameters, but to make them usable you need to include also the FilterExpression
.
for example you also need to add:
FilterExpression="name='{0}'"
Alternative you can add <SelectParameters>
as
<SelectParameters>
<asp:ControlParameter ControlID="NameFilter" Name="name"
PropertyName="Text" Type="String" />
</SelectParameters>
and use : SelectCommand = "SELECT * FROM factory WHERE name=@name"