我正在尝试为我的网格视图实现一个搜索函数。我的代码背后看起来像这样
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...
}
}到目前为止还没有问题。我唯一不喜欢的是,当搜索没有任何结果时,就没有显示网格视图。在这种情况下,我想要么显示一个空的网格视图,要么显示一个“无结果”的消息,或者仅仅显示一条消息。但是,我无法确定如何使用该筛选表达式确定sql数据源对象是否为空。所以请帮我解决这件事。
如果过滤器表达式导致了一个空的sqldatasource源,那么是否可以向用户显示一个空的网格视图?
提前谢谢!
发布于 2014-04-02 12:07:28
对网格视图使用空数据模板。
<ASP:GridView runat="server" ID="myGridView">
<EmptyDataTemplate>
Search result not found
</EmptyDataTemplate>
</ASP:GridView>https://stackoverflow.com/questions/22810734
复制相似问题