简体   繁体   English

ASP.NET仅插入带有下拉列表的详细信息视图

[英]ASP.NET Insert Only Details View with Drop Down List

I am using ASP.NET webforms and Entity Framework. 我正在使用ASP.NET Web表单和实体框架。 I'm trying to have just a simple insert form using a Details View. 我正在尝试使用“详细信息视图”制作一个简单的插入表单。 I do not want to edit, delete, or select entries from this Details View, only Insert new entries. 我不想编辑,删除或从“详细信息视图”中选择条目,仅插入新条目。

In the insert, I want to insert new people. 在插入中,我想插入新朋友。 The structure of a person is: Name, Manager, Location 一个人的结构是:姓名,经理,位置

I have two Entity Data Sources, one that represents Managers and one that represents Locations I have two DropDownLists in the InsertItemTemplate that can select manager and location. 我有两个实体数据源,一个代表管理者,一个代表位置。我在InsertItemTemplate中有两个DropDownLists,可以选择管理者和位置。

My problem is that when I place the DetailsView (DefaultMode = insert) and add the data source for the people entity, the DetailsView shows an entry from the database as well as the drop down lists and name fields. 我的问题是,当我放置DetailsView(DefaultMode = insert)并添加人员实体的数据源时,DetailsView显示数据库中的条目以及下拉列表和名称字段。 I might be missing something simple but I can't seem to get a DetailsView for insert only that has DropDownLists populated by other Entity Data Sources. 我可能缺少一些简单的东西,但是似乎无法获得只插入了DetailsView的DetailsView,而该视图具有由其他实体数据源填充的DropDownLists。

 <asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px" 
        DefaultMode="Insert" AutoGenerateInsertButton="True">
        <Fields>
            <asp:BoundField DataField = "Name" />
            <asp:TemplateField>
                <InsertItemTemplate>
                    <asp:DropDownList DataSourceID = "ManagerEntitySource" runat="server" />
                </InsertItemTemplate>
                <InsertItemTemplate>
                    <asp:DropDownList DataSourceID = "LocationEntitySource" runat="server" />
                </InsertItemTemplate>
            </asp:TemplateField>
        </Fields>
    </asp:DetailsView>
    <asp:EntityDataSource ID="AddEmployeeDataSource" runat="server" 
        ConnectionString="name=SafetyEntities" DefaultContainerName="SafetyEntities" 
        EnableFlattening="False" EnableInsert="True" EntitySetName="Employees">
    </asp:EntityDataSource>

Not sure if this will help, but if you only want insert mode, try removing the AutoGenerateInsertButton property, and add a CommandField with ShowInsertButton = True in the Fields property. 不知道这是否有帮助,但是如果您只想插入模式,请尝试删除AutoGenerateInsertButton属性,并在Fields属性中添加一个ShowInsertButton = True的CommandField。

<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px" 
    DefaultMode="Insert">
    <Fields>
        <asp:BoundField DataField = "Name" />
        <asp:TemplateField>
            <InsertItemTemplate>
                <asp:DropDownList DataSourceID = "ManagerEntitySource" runat="server" />
            </InsertItemTemplate>
            <InsertItemTemplate>
                <asp:DropDownList DataSourceID = "LocationEntitySource" runat="server" />
            </InsertItemTemplate>
        </asp:TemplateField>
        <asp:CommandField ShowInsertButton="True" />
    </Fields>
</asp:DetailsView>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM