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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top