在网格视图中显示不同的消息,因为没有绑定数据并且没有检索到结果
Display different messages in grid view for not having bound data and no results retrieved
我有一个 ASP.NET GridView
,当没有要显示的结果时,我想用消息 "No results found" 填充它。最初我不想绑定数据并让网格视图显示 "You still need to search"。
使用 EmptyDataTemplate
并仅将 null
绑定到网格视图只会显示一种类型的消息。有没有一种方法可以实现初始消息如上所述,并且在搜索时显示不同的消息并且没有结果绑定到 GridView
?
谢谢。
这真的很难看,但它可能是你需要的。
假设您在 EmptyDataTemplate 中有一个 ID 为 LabelNoData
的标签控件:
protected void GridView1_DataBound(object sender, EventArgs e)
{
Label Temp = GridView1.Controls[0].Controls[0].FindControl("LabelNoData") as Label;
if (GridView1.DataSource == null)
Temp.Text = "Please do a search";
else
Temp.Text = "No data found!";
}
我有一个 ASP.NET GridView
,当没有要显示的结果时,我想用消息 "No results found" 填充它。最初我不想绑定数据并让网格视图显示 "You still need to search"。
使用 EmptyDataTemplate
并仅将 null
绑定到网格视图只会显示一种类型的消息。有没有一种方法可以实现初始消息如上所述,并且在搜索时显示不同的消息并且没有结果绑定到 GridView
?
谢谢。
这真的很难看,但它可能是你需要的。
假设您在 EmptyDataTemplate 中有一个 ID 为 LabelNoData
的标签控件:
protected void GridView1_DataBound(object sender, EventArgs e)
{
Label Temp = GridView1.Controls[0].Controls[0].FindControl("LabelNoData") as Label;
if (GridView1.DataSource == null)
Temp.Text = "Please do a search";
else
Temp.Text = "No data found!";
}