Sau*_*abh 10
在中<FooterTemplate>,添加带有一些空数据文本的Label,并将其visible属性设置为false.
<FooterTemplate>
<table>
<tr>
<td>
<asp:Label ID="lblEmptyData"
Text="No Data To Display" runat="server" Visible="false">
</asp:Label>
</td>
</tr>
</table>
</FooterTemplate>
Run Code Online (Sandbox Code Playgroud)
现在检查绑定转发器时的数据,如果没有返回行,则make label可见,否则无法执行操作.
更多细节在这里.
正如@Saurabh所说,使用<FooterTemplate>添加一个Label在Text属性中指定你的消息,并将其visible属性设置为false,如下所示:
<FooterTemplate>
<%-- Label used for showing Error Message --%>
<asp:Label ID="ErrorMessage" runat="server" Text="Sorry!!" Visible="false">
</asp:Label>
</FooterTemplate>
Run Code Online (Sandbox Code Playgroud)
然后在代码隐藏中使用以下逻辑; 如果没有数据,则显示该消息,否则,显示如下数据:
protected void Repeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
Repeater rpt = sender as Repeater; // Get the Repeater control object.
// If the Repeater contains no data.
if (rpt != null && rpt.Items.Count < 1)
{
if (e.Item.ItemType == ListItemType.Footer)
{
// Show the Error Label (if no data is present).
Label ErrorMessage = e.Item.FindControl("ErrorMessage") as Label;
if (ErrorMessage != null)
{
ErrorMessage.Visible = true;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8297 次 |
| 最近记录: |