Both DataSource and DataSourceID are defined on ‘GridView1’. Remove one definition.
OK, so this is the message that you get most of the times when you try to bind your gridview or any other bindable controls, to multiple DataSources.
It happens most of the times when you bind your GridView control to an ObjectDataSouce or SqlDataSource on the design surface and then you try to bind the same GridView in code behind using the manual coding and sometimes it becomes necessary to do so in the scenarios of searching and manual paging etc.
(Binding to ObjectDataSource)
(Binding to manual DataSource)
GridView1.DataSource = null;
GridView1.DataSource = myDataTable;
GridView1.DataBind();
This is not going to solve the problem, the simples workaround is to set the DataSourceID to null.
GridView1.DataSourceID = null;
GridView1.DataSource = dt;
GridView1.DataBind();
now this is going to work perfectly fine but DataGrid required a page developer to write custom code to handle simple operations such as paging, sorting, editing or deleting data, the GridView control can automatically handle these operations provided its bound data source control supports these capabilities and we know that this kind of custom binding will kill any chances to automate your GridView to handle all these operations automatically.
Simplest way to resolve this issue is to display your required data to the client and then bind back the GridView to your original datasouce by setting the DataSourceID to null again. That will bring back all your automation functionality back to the GridView.
Cheers –
2 Steps Solutions
Re-engineering your business
July 23, 2008 at 7:09 am
Thanks Dude….
This is one common irritating msg tat I’m getting..
Cheers
April 10, 2009 at 10:00 am
that was great!!! thnx
April 21, 2009 at 4:47 am
Both DataSource and DataSourceID are defined on ‘GridView1′. Remove one definition.
thanq fr help’g me regarding ths query…
June 25, 2009 at 8:41 am
thankx alot it really works for me
July 15, 2009 at 4:30 pm
Thanks, jibrankhan, just the title of your article fixed my issue!
August 1, 2009 at 10:01 pm
can someone please explain how to do this? thanks
August 2, 2009 at 8:51 am
Can you show us using the code above how to modify the code to get the automation back?
August 2, 2009 at 9:41 am
Once you specifiy the ObjectDataSource back as the DataSource for your GridView, AutoEventHandlers will work fine again without writing any other piece of code.
GridView1.DataSourceID = null;
GridView1.DataSource = ObjectDataSource1;
GridView1.DataBind();
Hope it helps.
August 19, 2009 at 5:03 pm
thank u so much!!!!!!!!!!!!!
December 26, 2009 at 6:21 pm
I appreciate. very helpful
January 20, 2010 at 5:37 pm
Thanks a lot. That helped.
March 12, 2010 at 3:30 pm
Thanks…Your very first solution helped me….My problem is solved…Thanks again.
May 17, 2010 at 9:01 am
thnak u
June 18, 2010 at 10:13 am
Dude you are simply amazing! Thank you very much…
October 5, 2010 at 3:05 pm
It doesn´t works for me, there are another posible solution. Iam Using Entities
October 12, 2010 at 6:23 am
Jibran bhai
i have done as below but its giving error when i m deleting data
my code behing Search Button to search data
“string SP=”SearchBrand”;//store procedure name
DataTable dt= sr.ExecSP(SP, txtSearch.Text);//execute sp and return data in datatable
GVBrand.DataSourceID = string.Empty;
GVBrand.DataSource = dt;
GVBrand.DataBind();
GVBrand.DataSourceID = string.Empty;
GVBrand.DataSource = dbBrand;
GVBrand.DataBind();”
and its giving this error
Sys.WebForms.PageRequestManagerServerErrorException: The GridView ‘GVBrand’ fired event RowDeleting which wasn’t handled.
plz help me as soon as possible as i have to deploy my application tomorrow
October 12, 2010 at 9:32 am
Hi Abdullah – I don’t understand why would you bind the same control twice in the same piece of code?
Anyway, can you paste in the entire code? I’m not sure if you are using the custome written event handler for deleting rows or the one used through the data source?
What type of data source are you using?