Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Sir ,

When i submitted Save button in ASP.Net front end VB.net ,and back end Sql server , output displayed Error :


Both DataSource and DataSourceID are defined on 'GridView1'. Remove one definition.<b></b> please sent me full solution of this Error ASAP reply me.
Posted
Comments
Sunasara Imdadhusen 30-Sep-10 7:32am    
Which method you are using for Grid binding like using Datasource or ObjectDataSource?

1 solution

From: http://jibrankhan.wordpress.com/2008/06/18/both-datasource-and-datasourceid-are-defined-on-gridview1-remove-one-definition-bind-multiple-datasources-to-a-gridview-control/[^]

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 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 -
 
Share this answer
 
Comments
DawoodAbbasi 8-Feb-13 1:30am    
nice

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