1个回答
展开全部
repeater不像DATAGRID控件,可以动态添加列。
不过你可以定义自己的ITemplate。再设置repeater.ItemTemplate属性。
可以参考一下:
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")]
[ParseChildren(true)]
public class Template1 : Control, INamingContainer {
private ITemplate _messageTemplate = null;
private String _message = null;
public String Message {
get {
return _message;
}
set {
_message = value;
}
}
[
PersistenceMode(PersistenceMode.InnerProperty),
TemplateContainer(typeof(TemplateItem))
]
public ITemplate MessageTemplate {
get {
return _messageTemplate;
}
set {
_messageTemplate = value;
}
}
protected override void CreateChildControls() {
// If a template has been specified, use it to create children.
// Otherwise, create a single LiteralControl with the message value.
if (MessageTemplate != null) {
Controls.Clear();
TemplateItem i = new TemplateItem(this.Message);
MessageTemplate.InstantiateIn(i);
Controls.Add(i);
}
else {
this.Controls.Add(new LiteralControl(this.Message));
}
}
}
public class TemplateItem : Control, INamingContainer {
private String _message = null;
public TemplateItem(String message) {
_message = message;
}
public String Message {
get {
return _message;
}
set {
_message = value;
}
}
}
不过你可以定义自己的ITemplate。再设置repeater.ItemTemplate属性。
可以参考一下:
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")]
[ParseChildren(true)]
public class Template1 : Control, INamingContainer {
private ITemplate _messageTemplate = null;
private String _message = null;
public String Message {
get {
return _message;
}
set {
_message = value;
}
}
[
PersistenceMode(PersistenceMode.InnerProperty),
TemplateContainer(typeof(TemplateItem))
]
public ITemplate MessageTemplate {
get {
return _messageTemplate;
}
set {
_messageTemplate = value;
}
}
protected override void CreateChildControls() {
// If a template has been specified, use it to create children.
// Otherwise, create a single LiteralControl with the message value.
if (MessageTemplate != null) {
Controls.Clear();
TemplateItem i = new TemplateItem(this.Message);
MessageTemplate.InstantiateIn(i);
Controls.Add(i);
}
else {
this.Controls.Add(new LiteralControl(this.Message));
}
}
}
public class TemplateItem : Control, INamingContainer {
private String _message = null;
public TemplateItem(String message) {
_message = message;
}
public String Message {
get {
return _message;
}
set {
_message = value;
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询