[英]How can I use listitemCollection like placeholder
I used ListItemCollection in Web User Control. 我在Web用户控件中使用了ListItemCollection。 And I like it! 我喜欢它!
sample.asx sample.asx
public ListItemCollection Items {
get {
return this.ListBox1.Items;
}
}
TestForSampleascx.aspx TestForSampleascx.aspx
void Add(WebUserControls.Control3 ctrl1, WebUserControls.Control3 ctrl2) {
ListBox listbox = ctrl1.FindControl("ListBox1") as ListBox;
if (ctrl1.Items.Count > 0) {
foreach (ListItem li in listbox.Items) {
if (li.Selected)
ctrl2.Add(li.Text, li.Value);
}
}
}
void Remove(WebUserControls.Control3 ctrl) {
ListBox listbox = ctrl.FindControl("ListBox1") as ListBox;
if (ctrl.Items.Count > 0) {
int count = ctrl.Items.Count;
for (int i = count - 1; i > -1; i--) {
if (listbox.Items[i].Selected)
ctrl.Remove(listbox.Items[i].Value);
}
}
}
Look please! 请看! "ctrl.Items." “ ctrl.Items。” I used it. 我用了 But I want to use other control such as placeholder like: 但我想使用其他控件,例如占位符,例如:
public PlaceholderItemCollection Items {
get {
return this.Placeholder.Items;
}
}
or 要么
public PlaceholderItemCollection Controls {
get {
return this.Placeholder.Controls;
}
}
How can I do that? 我怎样才能做到这一点?
Why not just bind the datasource? 为什么不仅仅绑定数据源?
DataTable dt = logic_to_get_data();
ListBox1.DataSource = dt;
ListBox1.DataBind();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.