数据网格中的复选框问题
我在使用 DataGrid 中的复选框时遇到一些问题。复选框未绑定到填充数据网格的实体,因为实体上没有其属性。基本上我想做的是,当我检查复选框时,我将该行中的项目 ID 添加到要返回的列表中。我遇到的问题是,当我检查一些复选框和带有 DataPager 的页面时,它会取消选中第一页上的复选框并尝试删除它们,但 DataGrid 已经转到第二页,因此它会抛出空引用异常,因为它可以再也找不到那些物品了。我该如何解决这个问题?如果您需要我发布我的代码,请告诉我。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种方法是自定义实体框架为您创建的分部类。将布尔属性添加到实体类中。现在,您可以将复选框列绑定为任何其他列,数据将在分页之间维护。
然后,您可以枚举当前上下文中的项目,选择那些已检查的项目。
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.