根据下拉所选项目在表单视图中选择项目

发布于 2024-09-08 15:05:06 字数 165 浏览 10 评论 0原文

我正在尝试让下拉菜单和表单视图一起工作。我以前从未使用过表单视图。我也正在使用实体框架来做所有事情。这也是我第一次接触它。

我希望能够有一个下拉列表,它是从与表单视图相同的数据源填充的。到目前为止效果很好。

然后我希望能够更改下拉项,并更改显示的表单视图项。我不知道如何进行这项工作。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

九局 2024-09-15 15:05:06

您可以处理下拉列表的SelectedIndexChanged。然后您可以访问表单视图内的元素,如下所示:

(Label)fvCourseInstance.FindControl("lblDropDownValue").Text = ddlYourDropDown.SelectedValue

You can handle the SelectedIndexChanged of the dropdown. Then you can access the element inside the form view as:

(Label)fvCourseInstance.FindControl("lblDropDownValue").Text = ddlYourDropDown.SelectedValue
喵星人汪星人 2024-09-15 15:05:06

如果您设置

<asp:DropDownList AutoPostBack="True" OnSelectedIndexChanged="ddlType_SelectedIndexChanged"  ... />

然后您可以在后面的代码中使用事件处理程序为您的表单视图重新绑定数据源。

ddlType_SelectedIndexChanged(object sender, EventArgs e)
{
    // rebind your Form View from here.
}

If you set the

<asp:DropDownList AutoPostBack="True" OnSelectedIndexChanged="ddlType_SelectedIndexChanged"  ... />

Then you can have an event handler in the code behind rebind the DataSource for your Form View.

ddlType_SelectedIndexChanged(object sender, EventArgs e)
{
    // rebind your Form View from here.
}
瞄了个咪的 2024-09-15 15:05:06

我找到了一个可行的答案。在实体框架数据源上,我包含了一个 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文