If I want to set both gridview.datasource and gridview.datamember, which one I should set first? Is there any standard order about this? Thank you!
Asked
Active
Viewed 3,919 times
0
-
1Usually I set the datamember first. That way, when you set the datasource, it will refresh the grid using the datamember info. (If the datasource is a dataset, the datamember would be a table.) – Holger Brandt Jul 11 '12 at 16:16
2 Answers
1
I would prefer to set gridview.datasource
first and then only gridview.datamember
because you do not need to set gridview.datamember
property when binding to a data source that contains a single list or table.

Akash KC
- 16,057
- 6
- 39
- 59
0
Usually I set the datamember first. That way, when you set the datasource, it will refresh the grid using the datamember info. (If the datasource is a dataset, the datamember would be a table. If you set the datasource first and then the datamember, the datagrid will stay empty until explicitly refreshed.)
I do the same with all databound controls. For listboxes, I set the displaymember and valuemember first and then the datasource. The listbox then automatically has the proper info displayed.

Holger Brandt
- 4,324
- 1
- 20
- 35