0

I' workingon an ASP.NET project and in order to populate a GridView with datat from a SQL Server Database' table I use SQLDataSource and everythings goes just fine.

But now I need to add the option to sort the columns of the gridview(ASC-Desc), for that purpose I want to use a DataView and got the next code

DataView dv = new DataView();
 dv = (DataView)Ejemplo.Select(DataSourceSelectArguments.Empty);
 dv.Sort = "Departmento Desc";
 GridView1.DataSource = dv;

but got this error message:

Both DataSource and DataSourceID are defined on 'GridView1'.  Remove one definition.

Could you please help me and tell what am I doing wrong?

4
  • See datasource vs datasource Id. Looks like you want to use a datasource. Remove the DataSourceId that you have probably set declaratively for your GridView (look at your .ascx/.aspx file) Commented Oct 23, 2015 at 0:00
  • @Tung I just did but now the gridView doesn't appears at all Commented Oct 23, 2015 at 0:27
  • Did you call Gridview1.DataBind() after you assigned the datasource? Commented Oct 23, 2015 at 0:30
  • @Tung thanks, your answer helped me out...where should I mark your anserw as the one that fixed my problem? in the arrow up? Commented Oct 23, 2015 at 2:41

1 Answer 1

0

The GridView can be bound to a data source by either setting a datasourceId or by assigning a datasource object to the DataSource property, but not both. This is explained here.

To resolve the issue, remove the datasourceId from your .aspx/.ascx file.

@ElNeto, cheers

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.