DataSource和DatasourceId [英] DataSource and DatasourceId

查看:112
本文介绍了DataSource和DatasourceId的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#代码中使用DataSource并在aspDatasourceid中使用
当我运行应用程序时,它会生成错误,只应该使用一个定义。因此,当我消除dataSourceId或DataSource时,它会生成一些列不具有此类ID的Exsist。



这是什么解决方案。因为代码已经设计成它需要两者并且我被要求更新它..



现在我被困了.....

解决方案

它们可以互换使用,但你必须谨慎使用。例如如果您首先分配dataSourceID然后想要使用DataSource,那么在使用DataSource之前,您必须通过设置ControlID.DataSourceID =


Hello配合来清除datasourceID,



DataSourceID用于您使用Asp.net DataSource控件的情况,例如页面上的ObjectDataSource等,用于获取DataBound控件的数据。在这种情况下,CodeBehind方法名称提供给aspx页面上的DataSource控件,它使用这些方法从数据库中获取数据。



如果是DataSource,你得到的数据,例如在List或DataTable等中,并将其传递给CodeBehind中的DataBound控件的DataSource属性,然后调用其DataBind()方法。



我强烈建议只使用其中一种方法来绑定您的控件并修复您需要的Columns问题,以确保来自数据库的数据和通过DataSourceID方法或DataSource绑定的数据包含所有通过你的DataBound控件。



祝你好运


错误是显而易见的。您可以一次使用Only One数据源。要解决此错误,请快速检查:

转到页面的设计视图 - >找到控件 - >从中删除DataSourceID属性。

要了解详细信息,请访问以下链接:

MSDN:数据源控件概述 [ ^ ]

MSDN:

ASP.NET包含数据源控件,允许您使用不同类型的数据源,如数据库,XML文件或中间层业务对象。数据源控件连接到数据源并从中检索数据,并使其可供其他控件绑定,而无需代码。他们还可以支持修改数据。



MSDN:BaseDataBoundControl.DataSourceID属性 [ ^ ]

MSDN:

获取或设置数据绑定控件从中检索其数据项列表的控件的ID。





- Amit

In C# code "DataSource" is been used and in asp "Datasourceid"
when i run the application it generate error that only one definition should be used. so when i eliminate dataSourceId or DataSource it generates that some Columns don't Exsist with such id.

What is the solution this. as code already has been designed in such a way that it requires both and i have been asked to update it..

Now i am stuck.....

解决方案

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 = ""


Hello mate,

DataSourceID is used in case you have used Asp.net DataSource controls e.g. ObjectDataSource etc. on your page to fetch data for your DataBound control. In this case the CodeBehind method names are provided to DataSource control on the aspx page and it uses those methods to get data from database.

in case of DataSource you get the data for example in a List or DataTable etc. and pass it to the DataBound control's DataSource property in the CodeBehind and call its DataBind() method after that.

I strongly recommend to used only one of these methods to bind your control and to fix the Columns problem you need to make sure that the data coming from database and binding either through DataSourceID method or DataSource, contains all the Columns expected by your DataBound control.

Good luck


The error is obvious. You can use "Only One" data source at a time. To resolve this error, do a quick check:
Go to design view of the page -> Find the control -> Remove DataSourceID property from it.
To know the details visit the link below:
MSDN : Data Source Controls Overview[^]

MSDN:

ASP.NET includes data source controls that allow you to work with different types of data sources such as a database, an XML file, or a middle-tier business object. Data source controls connect to and retrieve data from a data source and make it available for other controls to bind to, without requiring code. They can also support modifying data.


MSDN : BaseDataBoundControl.DataSourceID Property[^]

MSDN:

Gets or sets the ID of the control from which the data-bound control retrieves its list of data items.



--Amit


这篇关于DataSource和DatasourceId的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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