Gridview没有显示linq中特定字段的数据

时间:2013-12-23 20:08:22

标签: linq gridview

我想在gridview中为特定的mail_id提供数据。但是,当我添加这个条件时,它没有显示任何东西。请帮忙

if (!IsPostBack)
{
    var mail = lblmail.Text;
    var result = from test in je.jobposting orderby test.post_date where test.c_j_email==mail  select test;
    foreach (var items in result)
    {
        gvjob.DataSource = result;
        gvjob.DataBind();
    }
}

1 个答案:

答案 0 :(得分:1)

这样更好吗?

{
  var mail = lblmail.Text;
  // here, I assume jobposting is a DataTable
  if (0 < je.jobposting.Rows.Count) {
    var result = from test in je.jobposting orderby test.post_date where test.c_j_email==mail  select test;
    if (result.Any()) {
      gvjob.DataSource = result;
      gvjob.DataBind();
    } else {
      Response.WriteLine("No Match for c_j_email=" + mail + ".");
    }
  } else {
    Response.WriteLine("<b>No Data in jobposting DataTable!</b>");
  }
}