gridview.Datasource and gridview.Datamember which I should set first?
-
20-06-2021 - |
题
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!
解决方案
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.
其他提示
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.