日期:2014-05-20  浏览次数:20807 次

linq + GridView页面数据没有显示
protected void Page_Load(object sender, EventArgs e)
  {
  //Database db = new Database();
  //string sql = "select id,field_code from field_baseinfo";
  //FarmlandManageGridView.DataSource = db.GetReader(sql);
  //FarmlandManageGridView.DataBind();
  //db.Close();
  FreshGridViewWithData();

  }


  //刷新GridView
  private void GridViewDataBind()
  {
  FarmlandManageGridView.DataSource = buildDisplayTable();
  FarmlandManageGridView.DataBind();
  }

  private void FreshGridViewWithData()
  {
  long danwei_id = DataTypeUtil.ParseLong(this.unitDropDownList.SelectedValue.ToString());
  int theYear = DataTypeUtil.ParseInt(this.yearDropDownList.SelectedItem.ToString());
  selectedlist = service.FindByDanweiAndYear(danwei_id, theYear);
  GridViewDataBind();
  }

  private DataTable buildDisplayTable()
  {
  var result = selectedlist.Select(p => new
  {
  id = p.id,
  field_code = p.crop_manageinfo.field_baseInfo.field_code,
  cropname = p.crop_manageinfo.breeds.crop.cropname,
  breed_name = p.crop_manageinfo.breeds.breed_name,
  seed_date = p.seed_date.ToShortDateString(),
  pumo_type = p.pumo_type,
  guangai_type = p.guangai_type
  });
  DataTable table = DataSetLinqOperators.CopyToDataTable(result);
  return table;
  }


我用linq+ gridview显示数据,但是没能将数据库中的数据显示出来。数据库连接等应该都是没有问题的,因为我用SQL测试,可以将数据正确地显示出来。

求解啊。谢谢。



------解决方案--------------------
return table;

加个断点