如果在repater中没有记录,我想在repater上显示消息,如“找不到记录”。 [英] if there is no records in repater I want to display message on repater like "No records found".

查看:82
本文介绍了如果在repater中没有记录,我想在repater上显示消息,如“找不到记录”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





如果在转发器中找不到记录,我想显示找不到记录这样的消息。我怎么能这样做?



请帮帮我...

谢谢....



If there are no records found in repeater I would like to display a message like "No records found". How can I do that?

Please help me...
Thank you....

推荐答案

如果您定义了HeaderTemplate或FooterTemplate,您可以在其中任何一个中添加任何HtmlControl或ServerControl,然后以编码方式显示/隐藏它。



If you have a HeaderTemplate or a FooterTemplate defined, you could add any HtmlControl or ServerControl inside of either of them and then programatically show/hide it in the codebehind.

<asp:Repeater id="Repeater1" runat="server" OnItemDataBound="">
 <HeaderTemplate>
  <h1>My Repeater Data</h1>
  <div id="NoRecords" runat="server" visible="false">
    No records are available.
  </div>
 </HeaderTemplate>
 <ItemTemplate>
 ...
 </ItemTemplate>
</asp:Repeater>







这是背后的代码






Here's the code behind

protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if (Repeater1.Items.Count < 1)
    {
        if (e.Item.ItemType == ListItemType.Header)
        {
            HtmlGenericControl noRecordsDiv = (e.Item.FindControl("NoRecords") as HtmlGenericControl);
            if (noRecordsDiv != null) {
              noRecordsDiv.Visible = true;
            }
        }
    }
}


创建div,可见false,如下所示

create div with visible false like below
<div id="emptydata" visible="false"  runat="server">
      There is no data currently
</div>



检查如何你有很多记录。如果没有记录,您可以跳过数据绑定到转发器。设置emptydata div的可见true



你也可以使用页眉或页脚模板

http://www.dotnetcurry.com/showarticle.aspx?ID=271 [ ^ ]

http://www.mindfiresolutions.com/How-to-show-Empty-Template-in-ASPNET-Repeater-control- 1102.php [ ^ ]

http://stackoverflow.com/questions/5271500/default-text-for-empty-repeater-control [ ^ ]


before you binding repeater check how many records you have. if no records you can skip data binding to repeater. set the visible true of emptydata div

you can also use header or footer template
http://www.dotnetcurry.com/showarticle.aspx?ID=271[^]
http://www.mindfiresolutions.com/How-to-show-Empty-Template-in-ASPNET-Repeater-control-1102.php[^]
http://stackoverflow.com/questions/5271500/default-text-for-empty-repeater-control[^]


public class EmptySource
        {
            public String Message { get; set; }
        }

check if datasource is empty then create instance of EmptySource:-

EmptySource _source = new EmptySource() { Message= "No record found"   };

and set dataSource of 'rpt' with _source like :-
rpt.datasorce = _source;
rpt.databind();


这篇关于如果在repater中没有记录,我想在repater上显示消息,如“找不到记录”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆