1

CompositeControl次のように定義されているクラスから派生したカスタム コントロールがあります。

[ToolboxData("<{0}:ContractControl runat=server></{0}:ContractControl>")]
public class ContractControl : CompositeControl
{
    private int contractID = 0;
    private ContractTileControl tileControl = null;
    private ContractDetailControl detailControl = null;

    private HtmlGenericControl contractMainDiv = null;

    public int ContractID
    {
        get { return this.contractID; }
        set { this.contractID = value; }
    }

    public ContractTileControl TileControl
    {
        get { return this.tileControl; }
        set { this.tileControl = value; }
    }

    public ContractDetailControl DetailControl
    {
        get { return this.detailControl; }
        set { this.detailControl = value; }
    }

    public ContractControl()
    {
        this.contractMainDiv = new HtmlGenericControl("div");
        this.contractMainDiv.ID = "contractMainDiv";
        this.contractMainDiv.Attributes.Add("class", "contractMain");
    }

    #region protected override void OnPreRender(EventArgs e)
    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);
        CreateChildControls();
    }
    #endregion

    #region protected override void CreateChildControls()
    protected override void CreateChildControls()
    {
        if (tileControl != null)
        {
            this.contractMainDiv.Controls.Add(tileControl);
        }

        if (detailControl != null)
        {
            this.contractMainDiv.Controls.Add(detailControl);
        }

        this.Controls.Add(contractMainDiv);
    }

    #endregion

}

それらの数をプレースホルダーコントロールに追加すると、それらは正常にレンダリングされますが、同じものをにバインドしようとすると、Repeater子複合コントロールがレンダリングされず、レンダリングされます。tileControldetailControlcontractMainDiv

リピーターは次のように定義されます。

<asp:Repeater ID="myRepeater" runat="server" EnableTheming="true">
  <HeaderTemplate>
    <table border="0" cellpadding="0" cellspacing="0">
  </HeaderTemplate>

  <ItemTemplate>
    <tr><td><easit:ContractControl ID="contractControl" runat="server" />
    </td></tr>
  </ItemTemplate>

  <FooterTemplate>
    </table>
  </FooterTemplate>
</asp:Repeater>

List<ContractControl>そして、最初に a を生成してから呼び出すことで、それにバインドします。

 List<ContractControl> controls = new List<ContractControl>();

 //Generate custom controls for each element in input dictionary

 //Create TileControl and DetailControl

 //Create ContractControl and add it to collection
 ContractControl contractControl = new ContractControl();
 contractControl.ContractID = contract.Contract.Id;
 contractControl.TileControl = tile;
 contractControl.DetailControl = detail;
 controls.Add(contractControl);

 myRepeater.DataSource = controls;
 myRepeater.DataBind();

それでも、結果のテーブルには適切な数の項目が含まれていますが、子の「CompositeControl」はまったくレンダリングされず、表示されるだけcontractMainDivです。

4

0 に答える 0