在ASP.net中使用GridView的文本框创建搜索选项

时间:2017-04-26 12:20:54

标签: c# asp.net search gridview textbox

我在C#中使用了gridview的搜索选项并且效果很好。现在我在ASP.net中尝试这样做但是它没有过滤数据。这些是我的代码。

 protected void btnsearch_Click(object sender, EventArgs e)
    {
        string qry = "Select *from Products where ProductName like '%" + tbsearch.Text + "%'";

        SqlDataSource1.SelectCommand = qry;

        DataView dv = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);

    }

我知道我遗漏了一些不会绑定数据但没有过滤的东西,有人可以帮我处理这些代码吗?我是第一次使用asp.net。

以下是SQLDataSource的源代码

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [ProductID], [ProductName], [SupplierID], [CategoryID], [UnitPrice] FROM [Products] WHERE ([ProductName] LIKE @ProductName + '%')">
                    <SelectParameters>
                        <asp:ControlParameter ControlID="tbsearch" Name="ProductName" PropertyName="Text" Type="String" />
                    </SelectParameters>
                </asp:SqlDataSource>

0 个答案:

没有答案