Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am getting an error that Both DataSource and DataSourceID are defined on 'GridView1'. Remove one definition. how to solve the querry in asp.net using c#. please find a better answer to me please.
Posted

You do not share the code piece and yet you seek/ask for 'better' answer (not sure how will you compare, yet!)

Ok, based on the error, it simply means that you have defined both DataSource as well as DataSourceID for the GridView1 that you are using.

Just comment the DataSourceID if you are providing a datatable as a source to DataSource property of the grid. Giving the datatable as a source is enough for the gridview to render and show the data.
If you are not having a Datatable assigned to a DataSource then comment the same and let DataSourceID do the job of feeding in the data to GridView1.
 
Share this answer
 
If you're using a datasource such as a SqlDataSource to initially databind the control but changing the datasource in the code behind at some point you need to set the DataSourceID to null when you assign the new datasource. This needs to be done before you call DataBind on the control
 
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