tags:

views:

31

answers:

1

Hello again;

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...

Helpme

A: 

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:

public void Add(string text, string value)  
{
    this.ListBox1.Items.Add(text, value);
}

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:

public ListItemCollection Items
{
    get
    {
        return this.ListBox1.Items;
    }
}

And then finally...

protected void btnAdd_Click(object sender, EventArgs e)
{
    if(Controltest1.Items.Count > 0)
    {
        foreach (ListItem li in listbox.Items )
        {
                if (li.Selected)
                {
                    Controltest2.Add(li.Text, li.Value);
                }
        }
    }
}
J.13.L
You are correct.Thanks a alot!!!
Phsika
Thanks for the comment can you mark it as answered? Thanks.
J.13.L
i do it my friend. i really thanks. And i want to contact on messenger? is it ok?
Phsika
my messenger: [email protected]
Phsika