Need to Show a message when DataList is Empty

拥有回忆 提交于 2019-12-04 17:36:30

问题


I'm using DataList to show records on Client Site of my web page. I need to show a message when my DataList is empty. Is there a property of Datalist? How to show that message?


回答1:


EmptyDataText property is not supported by DataList yet. But you can achieve almost same functionality using the following trick:

<FooterTemplate>
    <asp:Label Visible='<%#bool.Parse((DataList1.Items.Count==0).ToString())%>' 
               runat="server" ID="lblNoRecord" Text="No Record Found!"></asp:Label>
</FooterTemplate>

That is creating a Label in Footer of DataList, and make it visible only of DataList record count is 0.




回答2:


RowCount = Convert.ToInt32(DLMoreImages.Items.Count.ToString());
if (RowCount != null && RowCount < 1)
{
    DLMoreImages.Visible = false;
    LblerrorMess.Text = "No Record Found...";
}



回答3:


datalist.children.length === 0



回答4:


Simply use parameters in C#:

concat(Product, @space ,Subname)

...

cmd.Parameters.AddWithValue("@space", " ");



回答5:


try to use this code

if( dataList.Items.Count == 0 )
{
    dataList.Visible = false;
    lblMessage.Visible = true;
    lblMessage.Text = "No Record Found.";
}

lblMessage is a label control which initially hidden, beneath the DataList. You can write above code either in OnDataBind event or just after calling dataList.DataBind() method.



来源:https://stackoverflow.com/questions/2756466/need-to-show-a-message-when-datalist-is-empty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!