Translate

Thursday, April 21, 2011

Difference between datasource and datasourceid

In asp.net both datasource and datasourceid are properties of a databound control (eg dropdownlist ) that is used for binding it to some data.

The difference between the two is that datasource property is set to a collection.

eg
myDDl.DataSource=myCollection;

DatasourceID on the other hand is set to the ID of a datasource control. (A control that is specifically tailored to get data from a particular source. For eg access datasource to get data from MS access, sqldatasource to get data from SQL database and so on).

eg
myDDl.DataSourceID=mySQLDatasource;

Generally DataSourceID is used for developing quick and dirty prototypes. For professionally created web applications you would use the former (binding to a collection using datasource property) most of the time. However in professionally created sites you would come across instances where a treeview is bound to a SiteMapDataSource control using the datasourceid property.


1 comment:

Comments will appear once they have been approved by the moderator