i created web user control, it includes one listbox and also give propert with listdictionary to fill listbox.
if you lok below:
public ListDictionary Items { get { if (items == null) items = new ListDictionary(); return items; } set { items = value; } }
This help me for adding items into listbox.
http://img219.imageshack.us/img219/8664/dsfdsfsf.png
i send to message from mycontrol1 to webusercontrol2:
Test.aspx
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Controltest1.Items.Add('Adana Kebap', '1'); Controltest1.Items.Add('Urfa Kebap', '2'); Controltest1.Items.Add('Beyti', '3'); Controltest1.Items.Add('İskender', '4'); } } protected void btnAdd_Click(object sender, EventArgs e) { ListBox listbox= Controltest1.FindControl('ListBox1') as ListBox; if(listbox.Items.Count>0) { foreach (ListItem li in listbox.Items ) if (li.Selected) { Controltest2.Items.Add(li.Text, li.Value); } } }
but;
Controltest2.Items.Add(li.Text, li.Value);
this method don’t work, i gess…
I am assuming that at some point you are add your ListDictionary items to your ListBox1 controls items…
I would recommend creating a method in our user control like this:
Other wise you have to know the name of your ListBox control that is inside your user control…
Your other property could be changed to look like this:
And then finally…