【问题标题】:How to populate the form fields for updation purpose based on the dropdown list selected item in entity framework?如何根据实体框架中的下拉列表选定项填充表单字段以进行更新?
【发布时间】:2019-09-02 20:36:56
【问题描述】:

我正在使用 ASP .Net 中的内容管理系统,我一直在使用 EF 代码优先方法进行更新操作,但我无法根据下拉列表中的选定项目填充表单字段列表。

我尝试填充表单字段,但我无法这样做,我尝试了.Find() 之类的方法,但它不起作用

protected void ddlSelectCourse_SelectedIndexChanged(object sender, EventArgs e)
    {
        CourseInfo ci = new CourseInfo();
        var selectedId = ci.Id;

        var obj = irep.GetSingleCourse(selectedId);
        txtCourseName.Text = obj.CourseName;  

    }

我想填充 txtCourseName.Text 字段以填充课程名称

【问题讨论】:

    标签: c# asp.net entity-framework ef-code-first


    【解决方案1】:

    您不应该在更改事件中使用 EventArgs 中的索引吗?据我所知,您正在使用来自新“新”的 CourseInfo 对象的 selectedId,大概 id 是一个 int,在这种情况下它将是 0

    【讨论】:

    • 是的,绝对是从0开始的第一个索引。请提出更好的方法。
    • 我想我错了,EventArgs 可能没有索引。但是通过快速谷歌搜索, ddlSelectCourse.SelectedIndex.Value 可能有用吗?我不是很熟悉,只是想用我自己的逻辑:)
    猜你喜欢
    • 2017-08-03
    • 1970-01-01
    • 2014-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-11
    • 2023-04-09
    • 2019-07-24
    相关资源
    最近更新 更多