Question

Using code like this:

AppEntities data = new AppEntities();
var result = data.GIS_CONTRACTOR_TEST.Where(x => x.CONTRACTORNAME == txtSearch.Text);
GridView1.DataSource = result.ToList();
GridView1.DataBind();

I am able to filter data based on the text box. now my question is How I can check if the result is empty or not? I mean if I want to send a message to user that there is not such a value in the database? how can I do that?

Thanks

Était-ce utile?

La solution

if (result == null || result.ToList().Count == 0)
{
  // Display message
}

Autres conseils

You mean outside asking the list whether it has a length of 0? WHich would be the obvious thing to do?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top