0

msdn全体を検索していますが、正確に何を検索すればよいかわかりません...ユーザーコントロールの子要素にアクセスするにはどうすればよいですか?独自のhtml、htmlをレンダリングする新しいカスタムコントロールを作成したくありません出力は ascx ファイルの単純なリピーターで、次のようになります。

<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 を使用していくつかの作業を行い、結果セットをリピーターにバインドします...

4

3 に答える 3

1

私は自分で解決策を見つけました!

ascxコードビハインドで

[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();
}

app_code cs ファイルのどこかにありました

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

あなたのaspxページで

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

私がこのトラブルに巻き込まれる理由は基本的なものです。私はフロント エンドの開発者です。コード ビハインドで 1 つの html タグを見たくないのです。

于 2009-10-02T03:41:42.850 に答える
0

次に、子コントロールとしてアクセスしますか?

    protected void rpContent_itemdatabound(object sender, EventArgs e)
    {
        var theTabs = rpContent.FindControl("tabs") as tabs;
        if (theTabs != null)
            ...
    }
于 2009-10-01T16:56:57.547 に答える
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();
于 2009-10-01T02:52:16.647 に答える