문제

ASP.NET Dynamic Data의 스캐폴드 페이지에서 엔터티에 외래 키 필드가 있고 찾는 값이 기본 키 테이블에 없는 경우(예:드롭다운에 없으면 엔터티에 대한 편집 내용을 취소하고 검색된 외래 키 값을 해당 테이블에 추가한 다음 원래 엔터티로 돌아가야 합니다.

외래 키 필드 템플릿에 '새' 링크/버튼을 추가하면 검색된 값을 추가할 수 있는 새 창이 열리고(패널 표시) 드롭다운을 새로 고칠 수 있습니까?

도움이 되었습니까?

해결책

당신은 django admin ui;)와 같은 것을 의미합니다. 현재 해당 기능을 구현하려고 노력하고 있습니다. 코드가 작동하면 여기에 코드를 게시하겠습니다.

편집하다:

좋아, 나는 그것을 일하게하고, 완전한 장고 스타일을 완성했다 ... 설명하는 것이 길지만 실제로는 간단합니다.

생성 할 파일 :

admin_popup.master 멋진 팝업 페이지를 갖습니다 (헤더없이 관리자 마스터를 복사하십시오).

admin_popup.mas (insert.aspx 복사)

수정

admin.master.cs에 : 이것을 추가하십시오 :

protected override void OnInit(EventArgs e)
{
    base.OnInit(e);

    System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "refresh_fks", @"
    var fk_dropdown_id;
    function refresh() {
        __doPostBack(fk_dropdown_id,'refresh');
    };", true);
}

admin_popup.master 에서이 속성을 본문 태그에 추가하십시오 (Poup 크기를 조정하는 데 사용됩니다).

<body style="display: inline-block;" onload="javascript:resizeWindow();">

admin_popup.master.cs에서

protected override void  OnInit(EventArgs e)
{
    base.OnInit(e);

    System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "refresh_fks", @"
    var fk_dropdown_id;
    function refresh() {
        __doPostBack(fk_dropdown_id,'refresh');
    };", true);

    System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "resize_window", @"function resizeWindow() {
        window.resizeTo(document.body.clientWidth + 20, document.body.clientHeight + 40);
        window.innerHeight = document.body.clientHeight + 5;
        window.innerWidth = document.body.clientWidth;
    }", true);

    System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "update_parent", @"function updateParent() {
        window.opener.refresh();
    }", true);        
}

popup_insert.aspx.cs 에서이 두 기능을 교체하십시오.

protected void DetailsView1_ItemCommand(object sender, DetailsViewCommandEventArgs e) {
    if (e.CommandName == DataControlCommands.CancelCommandName)
        System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Close_Window", "self.close();", true); 
}

protected void DetailsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e) {
    if (e.Exception == null || e.ExceptionHandled) {
        System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Close_Window", "window.opener.refresh(); self.close();", true); 
    }
}

외국 Key_edit.ascx에서 linkbutton (id = linkbutton1)을 추가하고 외국 Key_edit.ascx.cs에 해당 함수를 바꾸십시오.

protected void Page_Load(object sender, EventArgs e) {
    if (DropDownList1.Items.Count == 0)
    {
        if (!Column.IsRequired) {
            DropDownList1.Items.Add(new ListItem("[Not Set]", ""));
        }

        PopulateListControl(DropDownList1);
        LinkButton1.OnClientClick = @"javascript:fk_dropdown_id = '{0}';window.open('{1}', '{2}', config='{3}');return false;".FormatWith(
            DropDownList1.ClientID,
            ForeignKeyColumn.ParentTable.GetPopupActionPath(PageAction.Insert),
            "fk_popup_" + ForeignKeyColumn.ParentTable.Name, "height=400,width=600,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,directories=no,status=no");
    }
    if (Request["__eventargument"] == "refresh")
    {
        DropDownList1.Items.Clear();
        if (!Column.IsRequired)
        {
            DropDownList1.Items.Add(new ListItem("[Not Set]", ""));
        }

        PopulateListControl(DropDownList1);
        DropDownList1.SelectedIndex = DropDownList1.Items.Count - 1;
    }
}

그리고 마지막으로 내가 사용하는 두 가지 범위 기능 (원하는 곳에 넣음).

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Web.DynamicData;
using System.Web.UI;

public static class Utils
{
    [DebuggerStepThrough]
    public static string FormatWith(this string s, params object[] args)
    {
        return string.Format(s, args);
    }

    public static string GetPopupActionPath(this MetaTable mt, string action)
    {
        return new Control().ResolveUrl("~/{0}/popup_{1}.aspx".FormatWith(mt.Name, action));
    }
}

Global.asax에서 해당 라인을 변경하여 새 경로를 등록하십시오.

Constraints = new RouteValueDictionary(new { action = "List|Details|Edit|Insert|popup_Insert" }),

좋아, 나는 아무것도 잊지 않았기를 바랍니다 ... 확실히 개선 될 수 있지만 작동합니다. 좋아, 일부 사람들이 그 유용한 사람들을 고수하기를 바랍니다. ASP.NET 동적 데이터가 훨씬 더 좋게 만들었습니다.). 나는 지금 다수의 관계를 살펴 보려고합니다.

다른 팁

수신:VB.net 사용자

만약 당신이 나처럼 동적 데이터가 얼마나 복잡하고 엉망인지에 대해 불만을 갖고 있었다면, 이것은 당신을 위한 것입니다!DD의 기본 사항을 이해하는 데에만 100시간 이상이 걸렸습니다(비록 제가 다른 데이터베이스 프로그래밍 기술에 매우 정통함에도 불구하고).

Guillaume의 솔루션은 Naughton의 솔루션보다 훨씬 쉽습니다.Naughton의 코드를 번역하려고 15시간 이상 시도한 후 Guillaume의 코드를 번역하려고 시도했는데 작업하는 데 단 2시간밖에 걸리지 않았습니다.여기도 같은 순서입니다.(메모:물론 cs 확장은 vb 확장으로 변환됩니다)

  1. admin.master.cs 지침을 무시하십시오.

  2. admin_popup.master 코드를 수행하세요.아직 VS 2008 이하 버전을 사용하고 있다면 인라인 블록 인용에 CSS 오류가 발생합니다.오류를 무시하십시오.

  3. 마스터 파일 OnInit 하위:

    Protected Overrides Sub OnInit(ByVal e As EventArgs)
    MyBase.OnInit(e)
    System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, Page.GetType, "refresh_fks", "     var fk_dropdown_id;     function refresh() {         __doPostBack(fk_dropdown_id,'refresh');     };", True)
    System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, Page.GetType, "resize_window", "function resizeWindow() {         window.resizeTo(document.body.clientWidth + 120, document.body.clientHeight + 120);         window.innerHeight = document.body.clientHeight + 5;         window.innerWidth = document.body.clientWidth;     }", True)
    System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, Page.GetType, "update_parent", "function updateParent() {        window.opener.location.reload(true);     }", True)
    

    서브 끝

  4. 사용자 정의 페이지 아래의 (popup_Insert.aspx.vb) 이벤트를 다음으로 바꾸십시오.

    Protected Sub DetailsView1_ItemCommand(ByVal sender As Object, ByVal e As DetailsViewCommandEventArgs)
    If e.CommandName = DataControlCommands.CancelCommandName Then
        System.Web.UI.ScriptManager.RegisterClientScriptBlock(Me, Me.GetType, "Close_Window", "self.close();", True)
    End If
    

    E.Exception E.Exception e.exceptionHandled 다음 system.web.ui.scriptmanager.registerClientsCriptbec (Me, Me.getType, "Close_window", window. Opener.Location.Reload (True);self.close (); ", true) 종료 if end sub.

  5. ForeignKey_Edit에서 사용자 정의 FieldTemplate을 만들고 이름을 ForeignLinkKey_Edit.ascx로 지정합니다.dropdownlist1 컨트롤 뒤에 두 개의 공백( )을 추가한 다음 그가 설명한 대로 asp:LinkButton을 만듭니다."__ 추가"와 같은 텍스트를 입력하세요.페이지 로드 기능을 다음으로 바꾸세요.

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    If DropDownList1.Items.Count = 0 Then
        If Not Column.IsRequired Then
            DropDownList1.Items.Add(New ListItem("[Not Set]", ""))
        End If
        PopulateListControl(DropDownList1)
    
        LinkButton1.OnClientClick = "javascript:fk_dropdown_id = '" & DropDownList1.ClientID & _
    

    " '; window.open ('"& forexyKeyColumn.parentTable.getActionPath ( "insert"). Replace ( "insert.aspx", "popup_insert.aspx") & _ ", '"& "fk_popup_"& forexekeyColumn.parentTable .name & " ', config ='& _"height = 400, 너비 = 400, 도구 모음 = 아니오, 메뉴 바 = 아니오, 스크롤 바 = 아니오, Resizable = no, location = no, directrice = no, status = no "& " '); 거짓 리턴;" 요청 ( "__ eventArgument") = "refresh"그런 다음 dropdownList1.Items.clear () column.isrequired에 dropdownList1.Add ( [[not set], "") populateListControl 인 경우 종료됩니다. (dropdownlist1) dropdownlist1.SelectedIndex = dropdownList1.Items.count -1 END IF END SUB

  6. 확장 기능을 무시하십시오.

  7. 제안된 업데이트된 라우팅을 수행합니다.메모:사용자 지정 경로를 사용하는 경우 라우팅이 정확해질 때까지 수정해야 합니다.

또는 여기에 두 개의 서버 컨트롤과 블로그 게시물을 만들었습니다.동적 데이터에 대한 팝업 삽입 제어 이는 거의 동일하지만 서버 컨트롤의 팝업 기능을 캡슐화하여 팝업 창에서 기본 창 및 팝업 버튼으로 값 BAK를 전달합니다.

VS2010 RC의 동적 데이터에 새로운 기능이 있습니까? 이 RC에 따라 동적 데이터의 간단한 마스터-디테일을 위해 이와 같은 해킹에 의지해야합니까?

VS2010 RC에서 DD의 일부 블로그 게시물을 기대합니다 ...

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top