2009-10-01 4 views
0

ive msdn에서 검색 한 적이 있지만 정확히 무엇을 검색해야하는지 알지 못합니다. 어떻게 사용자 정의 컨트롤의 자식 요소에 액세스합니까? 자체 HTML을 렌더링하는 새 사용자 지정 컨트롤을 만들지 않으려 고합니다. HTML 출력이 ASCX 파일의 간단한 리피터, 그것은 다음과 같습니다 .net에서 프로그래밍 방식으로 사용자 정의 컨트롤 요소를 검색하는 방법?

<asp:repeater id="rpContent" runat="server" onitemdatabound="rpContent_itemdatabound"> 
    <headertemplate><ul class="displaypanel"></headertemplate> 
    <itemtemplate> 
     <li class="on"> 
      <a href="javascript://">tab header</a> 
      <div> 
       what goes here is tab content 
      </div> 
     </li> 
    </itemtemplate> 
    <footertemplate> 
     </ul></footertemplate> 
</asp:repeater> 

내가 구현은 다음과 같이 할 :

<bni:tabs id="tabs" runat="server"> 
    <tab srcId="id1" /> 
    <tab srcId="id2" /> 
</bni:tabs> 

을 그래서 기본적으로 뒤에 코드에서, 나는 원하는 배열 또는리스트에서 자식 콜렉션을 검색하고, 일부 작업을 수행한다. ID를 사용하여 결과 세트를 제 리피터에 바인딩하십시오.

답변

0

해결책을 직접 찾았습니다. 의 App_Code에서 somehwere

[ParseChildren(true,"MyTabs")] 
public partial class QucikTabsControl : System.Web.UI.UserControl 
{ 

    private List<Tab> _myTabs; 
    [PersistenceMode(PersistenceMode.InnerProperty)] 
    public List<Tab> MyTabs 
    { 
     get 
     { 
      if (_myTabs == null) 
      { 
       _myTabs = new List<Tab>(); 
      } 
      return _myTabs; 
     } 

    } 
} 
protected void Page_Load(object sender, EventArgs e) 
{ 
    MyRepeater.DataSource = MyTabs.ToArray(); 
    MyRepeater.DataBind(); 
} 

뒤에 ASCX 코드

CS 파일 당신의 aspx 페이지에서

public class Tab 
    { 
    private string _sectionId; 

    public Tab(): this(String.Empty) 
     { 
     } 
    public Tab(string sectionid) 
    { 
     _sectionId = sectionid; 
    } 

    [Category("Behavior"), 
    DefaultValue(""), 
    Description("Section Id"), 
    NotifyParentProperty(true), 
    ] 
    public String SectionId 
    { 
     get 
     { 
      return _sectionId; 
     } 
     set 
     { 
     _sectionId = value; 
     } 
    } 
} 

<bni:tabs id="s" runat="server"> 
    <w:tab sectionid="23" /> 
</bni:tabs> 

이 문제에가는 이유 메신저가 기본입니다 : 내가 프런트 엔드 개발자는 코드에서 단일 HTML 태그를보고 싶지 않습니다.

0

나는 당신이 찾고있는 것이 목록에 데이터 바인딩하는 것이라고 믿습니다.

   <ItemTemplate> 
        <tr> 
         <td> <%# DataBinder.Eval(Container.DataItem, "Name") %></td> 
         <td> <%# DataBinder.Eval(Container.DataItem, "Ticker") %></td> 
        </tr> 
       </ItemTemplate> 

그리고 코드 숨김에서

:

class theData { public string Name { get; set; } public string Ticker { get; set; } } 
var source = new List<theData>(); 
rpContent.DataSource = source; 
rpContent.DataBind(); 
+0

아니요, 나는 탭 목록을 검색 한 다음 외부 중계 장치에 바인딩하려고합니다. – Ayyash

0

은 그럼 당신은 자식 컨트롤로 액세스 하시겠습니까?

protected void rpContent_itemdatabound(object sender, EventArgs e) 
    { 
     var theTabs = rpContent.FindControl("tabs") as tabs; 
     if (theTabs != null) 
      ... 
    } 
+0

아니요, 중재자 chhild에 액세스하지 않으려 고합니다. 컨트롤의 하위에 액세스하려고합니다. – Ayyash

관련 문제