动态数据在“编辑”页面上添加额外列

时间:2012-09-05 11:59:34

标签: asp.net dynamic-data asp.net-dynamic-data

我有一个动态数据站点,记录项目名称和客户名称。 “插入”页面工作正常,但编辑页面复制了编辑字段。 所以在编辑页面上会有:

项目名称:[TextBox]

项目名称:1 [TextBox]

在插入页面上,但是没关系:

项目名称:[TextBox]

有什么想法吗?

这是动态数据aspx页码:

<asp:DynamicDataManager ID="DynamicDataManager1" runat="server" AutoLoadForeignKeys="true">
    <DataControls>
        <asp:DataControlReference ControlID="FormView1" />
    </DataControls>
</asp:DynamicDataManager>

<h2 class="DDSubHeader">Edit Project</h2>

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:ValidationSummary ID="ValidationSummary1" runat="server" EnableClientScript="true"
            HeaderText="List of validation errors" CssClass="DDValidator" />
        <asp:DynamicValidator runat="server" ID="DetailsViewValidator" ControlToValidate="FormView1" Display="None" CssClass="DDValidator" />

        <asp:FormView runat="server" ID="FormView1" DataSourceID="DetailsDataSource" DefaultMode="Edit"
            OnItemCommand="FormView1_ItemCommand" OnItemUpdated="FormView1_ItemUpdated" RenderOuterTable="false">
            <EditItemTemplate>
                <table id="detailsTable" class="DDDetailsTable" cellpadding="6">
                    <asp:DynamicEntity ID="DynamicEntity1" runat="server" Mode="Edit" />
                    <tr class="td">
                        <td colspan="2">
                            <asp:LinkButton ID="LinkButton1" runat="server" CommandName="Update" Text="Update" />
                            <asp:LinkButton ID="LinkButton2" runat="server" CommandName="Cancel" Text="Cancel" CausesValidation="false" />
                        </td>
                    </tr>
                </table>
            </EditItemTemplate>
            <EmptyDataTemplate>
                <div class="DDNoItem">No such item.</div>
            </EmptyDataTemplate>
        </asp:FormView>

        <asp:LinqDataSource ID="DetailsDataSource" runat="server" EnableUpdate="true" />

        <asp:QueryExtender TargetControlID="DetailsDataSource" ID="DetailsQueryExtender" runat="server">
            <asp:DynamicRouteExpression />
        </asp:QueryExtender>
    </ContentTemplate>
</asp:UpdatePanel>

以下是Code Behind:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.DynamicData;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Halcyonetic.TimeService.Web.DynamicData.CustomPages.Projects
{
public partial class Edit : System.Web.UI.Page
{
    protected MetaTable table;

    protected void Page_Init(object sender, EventArgs e)
    {
        table = DynamicDataRouteHandler.GetRequestMetaTable(Context);
        FormView1.SetMetaTable(table);
        DetailsDataSource.EntityTypeName = table.EntityType.AssemblyQualifiedName;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        Title = table.DisplayName;

    }

    protected void FormView1_ItemCommand(object sender, FormViewCommandEventArgs e)
    {
        if (e.CommandName == DataControlCommands.CancelCommandName)
        {
            Response.Redirect(table.ListActionPath);
        }
    }

    protected void FormView1_ItemUpdated(object sender, FormViewUpdatedEventArgs e)
    {
        if (e.Exception == null || e.ExceptionHandled)
        {
            Response.Redirect(table.ListActionPath);
        }
    }
}
}

这是我的数据注释:

[MetadataType(typeof(ProjectMetadata))]
[ScaffoldTable(true)]
public partial class Project
{
}

[DisplayName("Projects")]
public partial class ProjectMetadata
{
    [Display(Name = "Project Name", Order = 1)]
    [ScaffoldColumn(true)]
    public object ProjectName { get; set; }

    [Display(Name = "Customer", Order = 2)]
    [ScaffoldColumn(true)]
    [UIHint("Customer")]
    public object Company { get; set; }
}

1 个答案:

答案 0 :(得分:0)

您发布的内容看起来像标准动态数据代码,但您可能希望更仔细地查看DBML或EDX文件中的关系(映射为关联)。看起来编辑模板是双重关联的东西......这很奇怪。对不起,这不是具体的,但也许会有所帮助。