Click here to Skip to main content
15,903,385 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how can i find that whether the datalist is empty or it has some data's.

Actually i'm using the code like this

DataList1.DataSource =some data src i hav added in this
DataList1.DataBind();


Pls help me.
Posted
Updated 10-Jan-10 23:37pm
v3

like below
DlEmp.DataSource = dtEmployeeDetails;
DlEmp.DataBind();

Now you can check
if(DlEmp!=null)
{
  if(DlEmp.Items.Count>0)
  {
    //Code to be executed
  }
  else
  {
    Response.Write("No Data");
  }
}
else
{
  Response.Write("No Data");
}

please let me know if you have any doubt
 
Share this answer
 
Hi,

You can find datalist having items or not? using following property
DataList1.Items.Count

Example:
if (DataList1 == null || DataList1.Items.Count == 0)
    Response.Write("Your dataList is EMPTY");
else
    Response.Write("Your dataList contain " + DataList1.Items.Count.ToString() + " item(s)");



If this answer is helpful to you, please provide rating. :)
Thanks,
Imdadhusen
 
Share this answer
 
Thank you Imdad..

But i'm still having doubt..
where do i add this code snippet.. whether before DataList1.DataBind();
or after to that..
 
Share this answer
 
Add after databind.

Thanks
Mehul Thakkar
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900