我在网络用户控件中使用了ListItemCollection。而且我喜欢它!
sample.asx
public ListItemCollection Items {
get {
return this.ListBox1.Items;
}
}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);
}
}
}快看啊!“ctrl.Items”我用过了。但是,我想使用其他控件,例如占位符,例如:
public PlaceholderItemCollection Items {
get {
return this.Placeholder.Items;
}
}或
public PlaceholderItemCollection Controls {
get {
return this.Placeholder.Controls;
}
}我怎么能这么做?
发布于 2009-04-06 00:22:22
为什么不直接绑定数据源呢?
DataTable dt = logic_to_get_data();
ListBox1.DataSource = dt;
ListBox1.DataBind();https://stackoverflow.com/questions/719429
复制相似问题