如何将一个数据表/数据集到一个ObjectDataSource控件 [英] How to convert a DataTable/DataSet into a ObjectDataSource

查看:195
本文介绍了如何将一个数据表/数据集到一个ObjectDataSource控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有被束缚到一个ObjectDataSource一个GridView。我有返回DataTable的方法。我怎么喂的DataTable到ObjectDataSource,以便在GridView在code更新?

I have a GridView that's tied to an ObjectDataSource. I have a method that returns a DataTable. How do I feed the DataTable to the ObjectDataSource so that the GridView is updated in code?

例如:

protected void Page_Load(object sender, EventArgs e) 
{
    MyClass obj = new MyClass(textbox.Text);
    DataTable dt = obj.GetData();

    ObjectDataSource1.DataSource = dt; 
}

是的,我知道,ODS没有DataSource属性。这就是为什么我坚持。

Yes, I know that the ODS does not have DataSource property. That's why I'm stuck.

如果你在想,为什么不直接分配GridView的数据表;答案是:我们想通过消耗臭氧层物质+ GridView的组合提供的自动分拣能力

If you're thinking, why not just assign the GridView the DataTable directly; the answer is: We like the auto-sorting capabilities offered by the ODS + GridView combo.

在谷歌所有搜索已返回是如何从ODS得到DT。我无法找到如何获得DT到ODS一个参考。这似乎是这是一个相当普遍的需求,因为人们从ASP.NET 1.1未来将有大量的code产生DT,如果他们想更新UI,他们将要得到DT到ODS。

All searches on Google have returned are how to get a DT from an ODS. I can't find a single reference on how to get a DT into the ODS. It would seem that this is quite a common need since people coming from ASP.NET 1.1 will have a lot of code that generates DT and if they want to update the UI, they will want to get the DT into the ODS.

推荐答案

试试这个:

(objDtSrcUsers.Select() as DataView).Table.DataSet 

这篇关于如何将一个数据表/数据集到一个ObjectDataSource控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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