Answered by:
Both DataSource and DataSourceID are defined in Gridview1

Question
-
By the way you guys in this C Forum ROCK. Other forums may take weeks or months before you get an answer.
I have a problem using C# on a ASp.NET site.
I have a Table Adapter with two queries. 1 to return all projects and the other to return projects on ProjectID parameter.
I use GridViewProject bound to ObjectDataSource1 to return al projects, but have a search textBox with a button on the same page.
I have included in my page_load event some code to do as follows:
if (textBox == "") // I have used == null to no avail as well.
GridViewProject.DataSource = myAdapter.GetProjectData();
else
GridViewProject.DataSource = myAdapter.GetProjectDataByProjectID(textBox); //textBox = TextBox1.Text
I have already declared my namespace for the ProjectTableAdapters and instantiated the ProjectdataTable class. Do anyone have an answer to this???
Monday, July 10, 2006 7:56 PM
Answers
-
Hi,
If you're already using ObjectDataSource for your GridView, you can define a new ControlParameter for your Select statement and connect it to the search box. No coding necessary...
Anyway, you can't have two data sources specified at once... Before setting DataSource property, try setting DataSourceId to empty string...
Andrej
Monday, July 10, 2006 8:08 PM -
I was able to get around it by un-naming my ObjectDataSource just before my query goes thru and then renaming it back on, once my query goes thru. In other words the ObjectDataSource ID will be nameless for the duration of the query. It seems like a dirty way to do it thou.
I tried before doing what you suggested and didn't have any luck. I'll try it again.
Monday, July 10, 2006 8:38 PM
All replies
-
Hi,
If you're already using ObjectDataSource for your GridView, you can define a new ControlParameter for your Select statement and connect it to the search box. No coding necessary...
Anyway, you can't have two data sources specified at once... Before setting DataSource property, try setting DataSourceId to empty string...
Andrej
Monday, July 10, 2006 8:08 PM -
I was able to get around it by un-naming my ObjectDataSource just before my query goes thru and then renaming it back on, once my query goes thru. In other words the ObjectDataSource ID will be nameless for the duration of the query. It seems like a dirty way to do it thou.
I tried before doing what you suggested and didn't have any luck. I'll try it again.
Monday, July 10, 2006 8:38 PM -
You will get this error if you use an object data source and also in your code try to specify the datasource of the gridview by using gridview.datasource = datasource as opposed to gridview.datasource = datasource.ID. I am getting this error also but I am not using an object data source, I am binding in code using the gridview.datasource = mydataset syntax. Why would I be getting this error if not using an object datasource and am always using same syntax to databind to the gridview?
Tuesday, October 30, 2007 7:34 PM -
I know this is 3 years later - but as a developer who runs to Google like a cryin' baby to his mama - I know how often I just see a error then google for answers. So since msdn came up on the top of my list I thought I would add my solution which is different from the others here.
I have been stung by this bee more than once
I tried doing things like DataSourceId = String.Empty;
And nothing seemed to work.
What you need to look for is NOT that you have both the DataSource and DataSourceID defined - but rather see if the value for the DataSource is bad.
I was assigning a dataset returned from a web service to a list box and I would get this error if the dataset was empty (I forget if it was an empty dataset or simply an empty/null value - but anyhoo the error was related to the datasource being bad not that there was bothdatasource and datasourceid)- Proposed as answer by ScottTheTall Thursday, September 22, 2011 4:41 PM
Saturday, April 11, 2009 10:51 AM -
Hey keef_riff_hard,
Thanks for bothering to post 3 years later :)
Just came across this problem.
The answer is really appreciated!
Thursday, June 25, 2009 8:43 PM -
Guys,
In my case it actually worked. I set both :
GridView2.DataSource = String.Empty;
GridView2.DataSourceID = String.Empty;Wednesday, March 10, 2010 6:08 PM -
Same comment, thanks for the "old" post which is still relevant.
setting source & ID to empty solved other issues as well.
Thursday, September 18, 2014 12:43 AM