2010-04-06 3 views
0

나는 내가 지금 내가 원하는이코드 숨김에서 XSL 템플릿 내의 컨트롤을 참조 하시겠습니까?

<asp:DropDownList ID="ddlSectors" AutoPostBack="true" runat="server" __designer:bind="{ddwrt:DataBind('i',ddlSectors,'SelectedValue','TextChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Sector')}"> 
        </asp:DropDownList> 
         <!--<SharePoint:FormField runat="server" id="ff7{$Pos}" ControlMode="New" FieldName="Sector" __designer:bind="{ddwrt:DataBind('i',concat('ff7',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Sector')}"/>--> 
         <SharePoint:FieldDescription runat="server" id="ff7description{$Pos}" FieldName="Sector" ControlMode="New"/> 

처럼 XSL 템플릿 내부 행에 컨트롤을 넣어 원하는 소재 기존 하나

에서 새로운 영문을 작성하여 만든 사용자 정의 NewItem.aspx이 내 코드 라이브러리에서 ddlSectors를 참조하지만 항상 객체의 인스턴스에 설정되지 않은 객체 참조를 throw합니다.

컨트롤이 XSL 템플릿 안에 있기 때문에 이것이 가능하다고 생각합니다.

그래서이 문제를 해결할 수있는 방법이 있습니까?

감사합니다.

답변

0

질문 : 드롭 다운 목록이 각 행에 렌더링됩니까?

그러나 부모 컨트롤을 참조하고 Control.FindControl 메서드를 사용하여 해당 컨트롤을 가져올 수 있습니다.

그러나 어떤 컨트롤이 부모가 될지 정확하게 알지 못하는 경우 사용자 지정 FindControlRecursive 메서드를 작성하여 컨트롤이 어디에 있든 검색 할 수 있습니다.

using System.Web.UI; 

namespace MyNamespace 
{ 
    public static class ControlExtensions 
    { 
     public static T FindControlRecursive<T>(this Control parentControl, string id) where T : Control 
     { 
      T ctrl = default(T); 

      if ((parentControl is T) && (parentControl.ID == id)) 
       return (T)parentControl; 

      foreach (Control c in parentControl.Controls) 
      { 
       ctrl = c.FindControlRecursive<T>(id); 

       if (ctrl != null) 
        break; 
      } 
      return ctrl; 
     } 
} 

그런 다음 FindControlRecursive<DropDownList>("ddlSectors")을 호출하면됩니다.

+0

안녕

덕분에 일 NewItem.aspx 양식 이렇게하면 드롭 다운 목록은 HTML 행 하나에 한 번만 렌더링됩니다. 코드 숨김에서 참조해야합니다. 감사합니다. –

+0

편집 된 답변보기 참조. –

0

감사합니다. Janis

아이디어가 저에게 영감을주었습니다. 여기

하지만

내가이 사용 저

Control FindControl2(ControlCollection col,string desiredID) 
    { 
     Control found=default(Control); 


     if (found != null) 
      return found; 
      for (int i = 0; i < col.Count; i++) 
      { 

       Control temp = col[i]; 
       if (temp != null) 
       { 
        if (temp.ID != null) 
        { 
         if (temp.ID == desiredID) 
         { 
          found = temp; 
          break; 
         } 
         else 
         { 
          if (found != null) 
           return found; 
          else 
          found=FindControl2(temp.Controls, desiredID); 
         } 
        } 
        else 
        { 
         if (found != null) 
          return found; 
         else 
         found = FindControl2(temp.Controls, desiredID); 
        } 


       } 
      } 

     return found; 
    } 

근무하는 기능이며 문제는이 사용자 정의 내부에있는 gridview에 또는 뭔가 에 있지

관련 문제