12

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?

leonyx
  • 849
  • 7
  • 15
  • 23
  • Funny enough, it seems not so. I was expecting some 'EmptyXXX' properties like the GridView has. – leppie May 03 '10 at 06:39

5 Answers5

29

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.

Tayyab Ali
  • 431
  • 4
  • 8
0
RowCount = Convert.ToInt32(DLMoreImages.Items.Count.ToString());
if (RowCount != null && RowCount < 1)
{
    DLMoreImages.Visible = false;
    LblerrorMess.Text = "No Record Found...";
}
LPL
  • 16,827
  • 6
  • 51
  • 95
leonyx
  • 849
  • 7
  • 15
  • 23
0
datalist.children.length === 0
bortunac
  • 4,642
  • 1
  • 32
  • 21
0

Simply use parameters in C#:

concat(Product, @space ,Subname)

...

cmd.Parameters.AddWithValue("@space", " ");
Osher Levy
  • 83
  • 7
0

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.

Nps
  • 1,638
  • 4
  • 20
  • 40