| 
                ■No25190 (ネクス さん) に返信
> ItemTemplate内では、すっきり分岐することはできないのでしょうか?
「すっきり分岐」とはいかないですが,仕事でやった時は,次のような「IfControl.ascx」なるものを作って,強引に分岐させていました。
# .ascxなのは,都合によりコンパイルの手間を省きたかったからだったりします。
コード自体は仕事の物から書き直しており (そもそも元はVB.NET),さらに動作確認をしていないのでちゃんと動く保証はないですが,参考になれば幸いです。
# プロジェクト自体がViewStateを使わない方針だったため,ViewStateがまともに扱えないかもしれません。
<%@ Control Language="C#" %>
<script runat="server">
    /// <summary>
    /// 判定対象となる条件を取得・設定します。
    /// </summary>
    public bool Condition = false;
    private ITemplate _thenTemplate = null, _elseTemplate = null;
    /// <summary>
    /// <see cref="Condition"/> が真の場合にインスタンス化される <see cref="ITemplate"/> を設定します。
    /// </summary>
    [TemplateContainer(typeof(IfControlContainer))]
    public ITemplate Then { set { _thenTemplate = value; } }
    /// <summary>
    /// <see cref="Condition"/> が偽の場合にインスタンス化される <see cref="ITemplate"/> を設定します。
    /// </summary>
    [TemplateContainer(typeof(IfControlContainer))]
    public ITemplate Else { set { _elseTemplate = value; } }
    /// <summary>
    /// <see cref="Then"/> および <see cref="Else"/> で指定された <see cref="ITemplate"/> 中で, Container.DataItem として利用するオブジェクトを取得・設定します。
    /// </summary>
    public object DataItem = null;
    public override void DataBind ()
    {
        base.OnDataBinding(EventArgs.Empty);
        Controls.Clear();
        if (HasChildViewState) ClearChildViewState();
        ITemplate targetTemplate = Condition ? _thenTemplate : _elseTemplate;
        if (targetTemplate == null) return;
        IfControlContainer container = new IfControlContainer(DataItem);
        targetTemplate.InstantiateIn(container);
        Controls.Add(container);
        TrackViewState();
    }
    /// <summary>
    /// <see cref="Then"/> や <see cref="Else"/> 中で,実際に Container として働くクラスです。
    /// </summary>
    public class IfControlContainer : Control, INamingContainer
    {
        public readonly object DataItem;
        public IfControlContainer (object dataItem)
        {
            DataItem = dataItem;
        }
    }
</script>
  |