0
J'ai utilisé ListItemCollection dans Web User Control. Et j'aime ça!Comment utiliser listitemCollection comme espace réservé
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);
}
}
}
Regardez s'il vous plaît! "ctrl.Items." Je l'ai utilisé. Mais je veux utiliser un autre contrôle, comme espace réservé comme:
public PlaceholderItemCollection Items {
get {
return this.Placeholder.Items;
}
}
ou
public PlaceholderItemCollection Controls {
get {
return this.Placeholder.Controls;
}
}
Comment puis-je faire cela?