结合从$ C $的LinqDataSource C-背后的GridView [英] Binding LinqDataSource from code-behind to Gridview

查看:136
本文介绍了结合从$ C $的LinqDataSource C-背后的GridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在.aspx页面上grdidview控制,我试图从code动态连接背后并绑定在GridView但不知何故,抛出了我一个错误...什么是错的这个code?任何帮助吗?

 的LinqDataSource LDS_POReport =新的LinqDataSource();
            LDS_POReport.ContextTypeName =DataContextDataContext;
            LDS_POReport.Selecting + =新的EventHandler< LinqDataSourceSelectEventArgs>(LinqDataSourcePO_Selecting);
            this.gvReport.DataSource =LDS_POReport;
            //this.gvReport.DataBind();

更新:

后,我更新code到

  this.gvReport.DataSource = LDS_POReport;

它工作正常,但是当我尝试整理我得到这个错误:

GridView控件gvReport解雇事件排序
这是不处理的。

我补充这一点,但没有效果。

  LDS_POReport.AutoPage = TRUE;
 LDS_POReport.AutoSort = TRUE;


解决方案

我的猜测的,你的问题就在这里:

  this.gvReport.DataSource =LDS_POReport;

以上code线试图将一个字符串分配给需要某种数据源的一个属性。我假设你真的打算分配的LinqDataSource 对象本身:

  this.gvReport.DataSource = LDS_POReport;

i have a grdidview control on the .aspx page and i am trying to connect dynamically from code behind and bind the gridview but somehow it throwing me an error... what is wrong with this code? any help?

  LinqDataSource LDS_POReport = new LinqDataSource();
            LDS_POReport.ContextTypeName = "DataContextDataContext";
            LDS_POReport.Selecting += new EventHandler<LinqDataSourceSelectEventArgs>(LinqDataSourcePO_Selecting);
            this.gvReport.DataSource = "LDS_POReport";
            //this.gvReport.DataBind();

Update:

after i update the code to

 this.gvReport.DataSource = LDS_POReport;

it works fine but when i try to sort i get this error:

The GridView 'gvReport' fired event Sorting which wasn't handled.

i added this but no effect.

 LDS_POReport.AutoPage = true;
 LDS_POReport.AutoSort = true;

解决方案

I guess that your problem is here:

this.gvReport.DataSource = "LDS_POReport";

The above code line attempts to assign a string to a property that expects some sort of data source. I assume that you really intended to assign the LinqDataSource object itself:

this.gvReport.DataSource = LDS_POReport;

这篇关于结合从$ C $的LinqDataSource C-背后的GridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆