Reputation: 3511
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?
Upvotes: 1
Views: 1370
Reputation: 41558
Sounds like you need to just set the DataSourceID from the markup, and set AutoGenerateSelectButton to true in your markup as well. Your question makes it sound like this is the behavior you are looking for. If you'd rather generate your own select buttons, you should look into either CommandFields, or just adding your own buttons with a CommandName of "Select".
Upvotes: 0
Reputation: 116977
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.
Upvotes: 1