Problems with checkboxes in Datagrids
I am having some trouble with CheckBoxes in a DataGrid. The CheckBoxes are not bound to the entities that开发者_高级运维 are populating the datagrid because there isn't a property on the entities for it. Basically what I am trying to do is when I check a CheckBox I add the ID of the item in that row to a list to be returned. The problem I am having is when I check some CheckBoxes and the page with the DataPager it uncheckes the CheckBoxes on the first page and tries to remove them but the DataGrid has already gone to the second page so it throws a null reference exception because it can't find those items anymore. How can I fix this? If you need me to post my code just let me know.
One approach to this is to customise the partial class that Entity Framework has created for you. Add your boolean property to the entity class. Now you can bind the checkbox column as any other column ant the data will be maintianed between paging.
You can then just enumerate through the items currently in the context select those have been checked.
精彩评论