A different approach you may want to try is doing this through
JavaScript on
the client. Unless you have a really good reason for going back to the
server each time they move an item to the other list then why do it?
Don't
waste the round trip if you don't have to... especially when something
like
this can be done VERY easily client side. If your interested let me
know
and I can send you some code that lets you do a multi-select move, a
double-click single move, and the same thing in reverse for removing
items.
It's all client side and you don't need to worry about all that server
side
business when it's probably not necessary.
-----Original Message-----
From: Lars Gyldenk=E6rne [mailto:lgy@n...]
Sent: Tuesday, June 25, 2002 8:40 AM
To: ASPX_Professional
Subject: [aspx_professional] RE: Dual Listboxes
Thanks Aiden,
This was just what I have been trying to do, It's just seems as if the
reference to ListBox1 is gone the moment the page leaves the server.
When I
hit the button copy nothing happens - I have a few controls on the page
so i
have enabled smartnavigation, but there is no difference wheater
smartnavigation is enabled or not.
Do you have any surgestions?
regards
Lars
-----Original Message-----
From: Montgomery, Aiden (External)
[mailto:Aiden.Montgomery@f...]
Sent: 25. juni 2002 15:21
To: ASPX_Professional
Subject: [aspx_professional] RE: Dual Listboxes
Hello again,
If I was to create what you are using I would not use the autopostback.
I would set the listboxes up in the way that you are doing this.
I would leave the AutoPostBack set to false.
Provide a button for the user to click possibly called "copy" or an
arrow
picture.
Create an event handler for this button. In here you can reference the
first listbox.
As you can set the listbox to accept multiple selections I have
provided an
example using both multiple and single.
void button_click(Object sender,EventArgs e)
{
// if you have the selection mode set to multi
ArrayList movinglist =3D new ArrayList();
foreach (ListItem li in listBox1.Items)
{
if (li.Selected)
{
movinglist.Add(li);
}
}
// Now you have all of the list items that the user slected
// If you only have the single selection mode set then you can use
ListItem li =3D listBox1.SelectedItem;
}
Now you can do what you want with the items. You can either enter them
into
the DataBase table which you use to populate the second ListBox, then
re-bind the list. Or you could attempt to add them directly into the
second
listbox. I have to admit that I have not used this option but I see no
reason why it should not work.
Place this line inside the if statement:
listBox2.Items.Add(li);
That should place them directly into the other listBox.
You may want to remove these items from the original list box:
listBox1.Remove(li);
This will remove the listitem from the list of items in the listbox.
HTH,
Aiden Montgomery
-----Original Message-----
From: Lars Gyldenk=E6rne [mailto:lgy@n...]
Sent: 25 June 2002 13:50
To: ASPX_Professional
Subject: [aspx_professional] RE: Dual Listboxes
Im populating the two listboxes with 2 dataset filled from a MS SQL2000
-
Stored Procedure.
I'm experienced difficulties when I want to catch the selected item.
ListBox1.DataSource =3D dsSomeThing;
ListBox1.DataValueField =3D "column1";
ListBox1.DataTextField =3D "column2";
When the page is rendered the first listbox displays alright - but when
click on an item i ListBox1 nothing happens.
To check if anything is happening i have added to labels which I try to
update at the selectevent
txtvalue.Text =3D ListBox1.SelectedItem.Value;
txtText.Text =3D ListBox1.SelectedItem.Text;
AutoPostBack =3D "true";
perhaps this gives you a better idea of what i'm up against.
regards,
Lars
-----Original Message-----
From: Montgomery, Aiden (External)
[mailto:Aiden.Montgomery@f...]
Sent: 25. juni 2002 14:26
To: ASPX_Professional
Subject: [aspx_professional] RE: Dual Listboxes
Hello,
The system that I was refering to is the one in the TabLayout.aspx page
(name from the Beta 2 version).
There is a list of components for each page area, and you have to
option to
move the components from one area to another.
The methods to create the functionality that you require all depends on
your
datasource.
If you are if you are populating the listbox's itemcollection using
databinding from a datasource then you will have to catch the "copy"
event;
Determine the selected item to be "copied" and then insert that into
the
datasource which you are using to populate the listbox. This could be
by
adding it to an already populated arraylist or inserting it into the
database and re-binding the target listbox.
If you can provide some more specific information on how you are
populating
your 2 listboxes I may be able to offer you a more sensible approach.
HTH,
Aiden Montgomery
-----Original Message-----
From: Lars Gyldenk=E6rne [mailto:lgy@n...]
Sent: 25 June 2002 12:02
To: ASPX_Professional
Subject: [aspx_professional] RE: Dual Listboxes
I'm sorry, but i have tried reading through the IBuySpy-Portal and
Store and
can't find the system do you have the name of the page?
perhaps it's just me who's blind or something
Lars
-----Original Message-----
From: Montgomery, Aiden (External)
[mailto:Aiden.Montgomery@f...]
Sent: 25. juni 2002 10:00
To: ASPX_Professional
Subject: [aspx_professional] RE: Dual Listboxes
If you look at the IBuySpy portal from Microsoft you will find that
they use
a system like this in the editing pages.
HTH
Aiden
-----Original Message-----
From: lgy@n... [mailto:lgy@n...]
Sent: 25 June 2002 08:23
To: ASPX_Professional
Subject: [aspx_professional] Dual Listboxes
Hi,
I have a listbox which populates a small dataset. I would like enable
the
user to "copy"/add one or more entries from the source-listbox to a
destination listbox.
Have any of you tried anything like is.
thanks in advance.
Lars