I get the above error in my C#/SQL/ASP.NET app because I have a datasource defined both in the ASPX file and the ASPX.CS file. But I want the Gridview to have selectable rows. So if I comment out the ASPX.CS datasource I get the above error but if I comment out the ASPX datasource I get the Gridview output but it is not selectable. How do I code this successfully?
C# – Both Datasource and DatasourceID are defined on GridView
asp.netcsql
Related Topic
- C# – Metadata file ‘.dll’ could not be found
- Sql – How to Join to first row
- C# – How to remedy “The breakpoint will not currently be hit. No symbols have been loaded for this document.” warning
- C# – reason for C#’s reuse of the variable in a foreach
- R – How far do you go with YAGNI?
- C# – Could not find a part of the path … bin\roslyn\csc.exe
Best Answer
You should only be specifying one or the other. If you want to give the data object directly to the grid, set the DataSource to be that object.
Otherwise, set the DataSourceID to the ID of the datasource that you want to be binding to, and let it do it's thing.
Selectable rows shouldn't have anything to do with where the data is coming from. You can select a row by setting the SelectedRow property. Making them selectable in the UI is a whole different topic.