首页 新闻 赞助 找找看

linq + GridView页面数据没有显示

0
悬赏园豆:10 [已关闭问题] 关闭于 2011-11-23 10:16

 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测试,可以将数据正确地显示出来。

求解啊。谢谢。

Jerikc的主页 Jerikc | 初学一级 | 园豆:172
提问于:2011-11-22 19:48
< >
分享
所有回答(1)
0

跟踪看看,DataTable table这个是否有内容了,没有的话,是linq查询的问题或条件设置不对

如果有的话,gridview的设置可能存在问题

2012 | 园豆:21228 (高人七级) | 2011-11-23 08:26
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册