Itemplate自定义模板列

前些时候写DataGrid合并行效果,在网上偶然必然了这个接口的实现。
ContractedBlock.gif ExpandedBlockStart.gif Itemplate例子Msdn
 1None.gifusing System;
 2None.gifusing System.Web;
 3None.gifusing System.Web.UI;
 4None.gif
 5ExpandedBlockStart.gifContractedBlock.gifnamespace TemplateControlSamples dot.gif{
 6InBlock.gif
 7ExpandedSubBlockStart.gifContractedSubBlock.gif    public class TemplateItem : Control, INamingContainer dot.gif{
 8InBlock.gif        private String     _message         = null;
 9InBlock.gif
10ExpandedSubBlockStart.gifContractedSubBlock.gif        public TemplateItem(String message) dot.gif{
11InBlock.gif            _message = message;
12ExpandedSubBlockEnd.gif        }

13InBlock.gif
14ExpandedSubBlockStart.gifContractedSubBlock.gif        public String Message dot.gif{
15InBlock.gif
16ExpandedSubBlockStart.gifContractedSubBlock.gif           get dot.gif{
17InBlock.gif              return _message;
18ExpandedSubBlockEnd.gif           }

19ExpandedSubBlockStart.gifContractedSubBlock.gif           set dot.gif{
20InBlock.gif              _message = value;
21ExpandedSubBlockEnd.gif           }

22ExpandedSubBlockEnd.gif        }

23ExpandedSubBlockEnd.gif    }

24InBlock.gif
25InBlock.gif    [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")]
26InBlock.gif    [ParseChildren(true)]
27ExpandedSubBlockStart.gifContractedSubBlock.gif    public class Template1 : Control, INamingContainer dot.gif{
28InBlock.gif
29InBlock.gif        private ITemplate  _messageTemplate = null;
30InBlock.gif        private String     _message         = null;
31InBlock.gif
32ExpandedSubBlockStart.gifContractedSubBlock.gif        public String Message dot.gif{
33InBlock.gif
34ExpandedSubBlockStart.gifContractedSubBlock.gif           get dot.gif{
35InBlock.gif              return _message;
36ExpandedSubBlockEnd.gif           }

37ExpandedSubBlockStart.gifContractedSubBlock.gif           set dot.gif{
38InBlock.gif              _message = value;
39ExpandedSubBlockEnd.gif           }

40ExpandedSubBlockEnd.gif        }

41InBlock.gif
42InBlock.gif        [
43InBlock.gif            PersistenceMode(PersistenceMode.InnerProperty),
44InBlock.gif            TemplateContainer(typeof(TemplateItem))
45InBlock.gif        ]
46ExpandedSubBlockStart.gifContractedSubBlock.gif        public ITemplate MessageTemplate dot.gif{
47ExpandedSubBlockStart.gifContractedSubBlock.gif           get dot.gif{
48InBlock.gif              return _messageTemplate;
49ExpandedSubBlockEnd.gif           }

50ExpandedSubBlockStart.gifContractedSubBlock.gif           set dot.gif{
51InBlock.gif              _messageTemplate = value;
52ExpandedSubBlockEnd.gif           }

53ExpandedSubBlockEnd.gif        }

54InBlock.gif
55ExpandedSubBlockStart.gifContractedSubBlock.gif        protected override void CreateChildControls() dot.gif{
56InBlock.gif
57InBlock.gif           // If a template has been specified, use it to create children.
58InBlock.gif           // Otherwise, create a single LiteralControl with the message value.
59InBlock.gif
60ExpandedSubBlockStart.gifContractedSubBlock.gif           if (MessageTemplate != nulldot.gif{
61InBlock.gif              Controls.Clear();
62InBlock.gif              TemplateItem i = new TemplateItem(this.Message);
63InBlock.gif              MessageTemplate.InstantiateIn(i);
64InBlock.gif              Controls.Add(i);
65ExpandedSubBlockEnd.gif           }

66ExpandedSubBlockStart.gifContractedSubBlock.gif           else dot.gif{
67InBlock.gif              this.Controls.Add(new LiteralControl(this.Message));
68ExpandedSubBlockEnd.gif           }

69ExpandedSubBlockEnd.gif        }

70ExpandedSubBlockEnd.gif    }

71ExpandedBlockEnd.gif}
   

感觉挺有意思,不过还没有时间仔细的研究。。先做个标记,回头有时候或有必要的时候在研究下。。。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值