根据下拉所选项目在表单视图中选择项目
我正在尝试让下拉菜单和表单视图一起工作。我以前从未使用过表单视图。我也正在使用实体框架来做所有事情。这也是我第一次接触它。
我希望能够有一个下拉列表,它是从与表单视图相同的数据源填充的。到目前为止效果很好。
然后我希望能够更改下拉项,并更改显示的表单视图项。我不知道如何进行这项工作。
I am trying to get a drop down and a form view to work together. I've never used form views before. I also am using the entity framework to do everything. This is also my first time with it.
I want to be able to have a drop down, that is populate from the same data source as the form view. So far that works fine.
I then want to be able to change the drop down item, and it change the form view item that is displayed. I cannot figure out how to make this work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以处理下拉列表的SelectedIndexChanged。然后您可以访问表单视图内的元素,如下所示:
You can handle the SelectedIndexChanged of the dropdown. Then you can access the element inside the form view as:
如果您设置
然后您可以在后面的代码中使用事件处理程序为您的表单视图重新绑定数据源。
If you set the
Then you can have an event handler in the code behind rebind the DataSource for your Form View.
我找到了一个可行的答案。在实体框架数据源上,我包含了一个 where 参数,它是指向下拉列表的控件。因此,当我更改下拉列表时,我有一个事件处理程序,如果未选择任何内容,则将表单视图置于插入模式;如果选择了某些内容,则将表单视图置于只读模式。我不知道这是否是最好的方法,但目前工作正常。稍后我将尝试了解更多有关使用表单视图的信息,以了解其他人如何使用它们。
I found an answer that will work. On the entity framework data source I included a where parameter that is a control that points to the drop down. So when I change the drop down I have an event handler that puts the form view in either insert mode if nothing was selected or read only mode if I selected something. I don't know if this is the best way, but it is working ok for now. Later I'll try and learn more about using form views to see how other people use them.