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



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

项目名称:[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>

以下是代码背后:

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; }
}

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

相关内容

  • 没有找到相关文章

最新更新