C# 实现搜索功能
我正在尝试为我的gridview实现一个搜索函数。我的代码隐藏看起来像这样C# 实现搜索功能,c#,asp.net,gridview,C#,Asp.net,Gridview,我正在尝试为我的gridview实现一个搜索函数。我的代码隐藏看起来像这样 protected void ButtonSearch_Click(object sender, EventArgs e) { string title = TextBoxSearchTitle.Text; string artist = TextBoxSearchArtist.Text; string genre = DDLSearch.SelectedValue
protected void ButtonSearch_Click(object sender, EventArgs e)
{
string title = TextBoxSearchTitle.Text;
string artist = TextBoxSearchArtist.Text;
string genre = DDLSearch.SelectedValue;
if (genre == "Alle")
{
return;
}
else
{
SqlDataSource1.FilterExpression = String.Format("Title LIKE '%{0}%' AND Artist LIKE '%{1}%' AND Genre ='{2}'", title, artist, genre);
//figure out if table will be empty and do something...
}
}
到目前为止,它的运行没有任何问题。我唯一不喜欢的是当搜索没有任何结果时,没有显示gridview。在这种情况下,我想显示一个空的gridview,并显示一条消息“No results”或其他内容,或者只显示一条消息。但是我不知道如何使用filterexpression确定我的sqldatasource对象是否为空。所以请帮我解决这个问题
如果过滤器表达式产生空的sqldatasource,是否可以向用户显示空的gridview
提前谢谢 为网格视图使用空数据模板
<ASP:GridView runat="server" ID="myGridView">
<EmptyDataTemplate>
Search result not found
</EmptyDataTemplate>
</ASP:GridView>
未找到搜索结果