Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.....
Posted
Comments
saguptamca 26-Sep-13 4:11am    
provide some code, what r u trying to say

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 = ""
 
Share this answer
 
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
 
Share this answer
 
v2
Comments
hira_1 26-Sep-13 5:48am    
I Agree :)

See what is happening the code i have been given .. under search button alla columns are getting bind using Data table and dataSource . the column defined in Datasource holding differnt ColumnId.

And in asp DatasourceId has been assigned which contain column name with different id . by id i mean when iam binding the column usiong abel or linkbutton that is used.
So as i remove the Any one DataSource or
DataSourceid the i did not get the required result .. if you like to see the code i'll also paste the code here.
Azee 26-Sep-13 13:38pm    
Yes that would be better, please do.
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900