ASP.NET - DataSourceID 和 DataSource 有什么区别?

发布于 2024-11-30 02:56:53 字数 202 浏览 3 评论 0原文

DataSourceID和DataSource与控件属性有什么区别?我可以互换使用它们吗?

当我尝试在设计时设置 DataSource 属性时,通过在 aspx 页面上键入它,我收到一个异常,显示“无法以声明方式设置 'DataSource' 属性。”。但是当我使用属性窗口更改DataSource时,它没有给出任何异常。

What is the difference of DataSourceID and DataSource from the controls' attribute? Can I use them interchangeably?

When I try to set DataSource property at the design time, by typing it on the aspx page, I get an exception that says "The 'DataSource' property cannot be set declaratively.". But when I use property window to change the DataSource, it gives no exception.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

顾铮苏瑾 2024-12-07 02:56:53

DataSource 指实际的数据源对象,可以是.NET提供的数据源控件(如ObjectDataSource、SqlDataSource)或实际的数据对象,如DataTable、对象集合等。

DataSourceID 是 .NET 提供的数据源控件的字符串标识符,此属性的存在使得数据绑定控件和相应的数据源可以在设计时在标记中关联起来。在内部,控件将使用提供的 ID 查找实际的数据源控件。

DataSource refers to actual data source object which can be .NET provided data source controls (such as ObjectDataSource, SqlDataSource) or actual data objects such as DataTable, Collection of objects etc.

DataSourceID is the string identifier for .NET provided data source control and this property exists so that data-bound control and corresponding data source can be associated at the design time in markup. Internally, the control would look up for actual data source control using the id provided.

巨坚强 2024-12-07 02:56:53

DataSourceID 可以分配其他类型的数据源控件的 ID,例如 ObjectDataSource XmlDataSource

数据源控件概述:

http://msdn.microsoft.com/en-us/ Library/ms227679.aspx

还有各种其他类型的数据源控件,或者您也可以开发自己的数据源控件。

当您想要直接提供控件源(例如 DataSetDataTable)时,请使用 Datasource

DataSourceID can be assigned an ID of other data source control of type such as ObjectDataSource XmlDataSource .

Data Source Controls overview:

http://msdn.microsoft.com/en-us/library/ms227679.aspx

There are various other types of data source controls as well or you can develop your own as well.

Datasource is used when you want to directly give the source to control such as DataSet or a DataTable

顾挽 2024-12-07 02:56:53

数据源:< /a> 获取或设置数据绑定控件从中检索其数据项列表的对象。 (继承自BaseDataBoundControl。)

DataSourceID: 获取或设置数据绑定控件从中检索其数据项列表的控件的 ID。 (继承自DataBoundControl。)

其次,它们可以互换使用,但必须小心使用。例如,如果您先分配dataSourceID,然后想使用DataSource,那么在使用DataSource之前,您必须通过设置清除datasourceID ControlID.DataSourceID = ""

DataSource: Gets or sets the object from which the data-bound control retrieves its list of data items. (Inherited from BaseDataBoundControl.)

DataSourceID: Gets or sets the ID of the control from which the data-bound control retrieves its list of data items. (Inherited from DataBoundControl.)

Secondly they can be used interchangeably, but you have to use carefully. e.g. If you first assign dataSourceID and then want to use DataSource, then before using DataSource, you have to clear the datasourceID by setting ControlID.DataSourceID = ""

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文