سؤال

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

هل كانت مفيدة؟

المحلول

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

نصائح أخرى

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top