Both DataSource and DataSourceID are defined on ‘GridView1’. Remove one definition. – Bind multiple datasources to a gridview control

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)

 ObjectDataSource Binding

(Binding to manual DataSource)

GridView1.DataSource = null;
GridView1.DataSource = myDataTable;
GridView1.DataBind();

This is not going to solve the problem, the simples workaround is Read the rest of this entry »