473,847 Members | 1,806 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reorder listbox items in asp.net

Is it possible to reorder items in a listbox server control by having the
user select an item and then click an up or down button? ... how?
Or is this something that can only be achieved client side?

thanks
Nov 17 '05 #1
3 8135
hi,

of course it's possible and yes, you should do it in client side, otherwise
you would get a lot of roundtrip
find the code below for doing just that
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

<script>
function GoDown()
{
if ( document.forms[0].SelectOrder.se lectedIndex == -1 ) return;
document.forms[0].UpButton.disab led =
document.forms[0].DownButton.dis abled = true;

if ( document.forms[0].SelectOrder.se lectedIndex<
document.forms[0].SelectOrder.op tions.length-1)
{
var selIndex = document.forms[0].SelectOrder.se lectedIndex;
var text = document.forms[0].SelectOrder.op tions[ selIndex ].text;
var value = document.forms[0].SelectOrder.op tions[ selIndex ].value;
document.forms[0].SelectOrder.op tions[ selIndex ].text =
document.forms[0].SelectOrder.op tions[ selIndex +1].text;
document.forms[0].SelectOrder.op tions[selIndex ].value =
document.forms[0].SelectOrder.op tions[ selIndex +1].value;
document.forms[0].SelectOrder.op tions[ selIndex +1].text = text;
document.forms[0].SelectOrder.op tions[ selIndex +1].value = value;

document.forms[0].SelectOrder.se lectedIndex++;
}
document.forms[0].UpButton.disab led =
document.forms[0].DownButton.dis abled = false;
}

function GoUp()
{
if ( document.forms[0].SelectOrder.se lectedIndex == -1 ) return;

document.forms[0].UpButton.disab led =
document.forms[0].DownButton.dis abled = true;

if ( document.forms[0].SelectOrder.se lectedIndex>0)
{
var selIndex = document.forms[0].SelectOrder.se lectedIndex;
var text = document.forms[0].SelectOrder.op tions[ selIndex ].text;
var value = document.forms[0].SelectOrder.op tions[ selIndex ].value;
document.forms[0].SelectOrder.op tions[ selIndex ].text =
document.forms[0].SelectOrder.op tions[ selIndex -1].text;
document.forms[0].SelectOrder.op tions[selIndex ].value =
document.forms[0].SelectOrder.op tions[ selIndex -1].value;
document.forms[0].SelectOrder.op tions[ selIndex -1].text = text;
document.forms[0].SelectOrder.op tions[ selIndex -1].value = value;

document.forms[0].SelectOrder.se lectedIndex--;
}
document.forms[0].UpButton.disab led =
document.forms[0].DownButton.dis abled = false;
}

function GenerateIDsSubm it()
{

//see the order of the select and set
var s= new String();
for( var i=0; i< document.forms[0].SelectOrder.op tions.length; i++)
s=s + "," + document.forms[0].SelectOrder.op tions[i].value;
document.forms[0].userIDs.value = s.slice(1, s.length);
document.all["GetStatsBT N"].click();

}

</script>

<input type="button" value="Send" onclick="Genera teIDsSubmit();" >

<input type="button" id="UpButton" name="UpButton" value="Up"
onclick="GoUp() ;"><br>
<input type="button" id="DownButton " name="DownButto n" value="Down"
onclick="GoDown ();">
<select id="SelectOrder " size=10 name="SelectOrd er"></select>

"CodeRazor" <Co*******@disc ussions.microso ft.com> wrote in message
news:74******** *************** ***********@mic rosoft.com...
Is it possible to reorder items in a listbox server control by having the
user select an item and then click an up or down button? ... how?
Or is this something that can only be achieved client side?

thanks

Nov 17 '05 #2
thank you

"Ignacio Machin ( .NET/ C# MVP )" wrote:
hi,

of course it's possible and yes, you should do it in client side, otherwise
you would get a lot of roundtrip
find the code below for doing just that
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

<script>
function GoDown()
{
if ( document.forms[0].SelectOrder.se lectedIndex == -1 ) return;
document.forms[0].UpButton.disab led =
document.forms[0].DownButton.dis abled = true;

if ( document.forms[0].SelectOrder.se lectedIndex<
document.forms[0].SelectOrder.op tions.length-1)
{
var selIndex = document.forms[0].SelectOrder.se lectedIndex;
var text = document.forms[0].SelectOrder.op tions[ selIndex ].text;
var value = document.forms[0].SelectOrder.op tions[ selIndex ].value;
document.forms[0].SelectOrder.op tions[ selIndex ].text =
document.forms[0].SelectOrder.op tions[ selIndex +1].text;
document.forms[0].SelectOrder.op tions[selIndex ].value =
document.forms[0].SelectOrder.op tions[ selIndex +1].value;
document.forms[0].SelectOrder.op tions[ selIndex +1].text = text;
document.forms[0].SelectOrder.op tions[ selIndex +1].value = value;

document.forms[0].SelectOrder.se lectedIndex++;
}
document.forms[0].UpButton.disab led =
document.forms[0].DownButton.dis abled = false;
}

function GoUp()
{
if ( document.forms[0].SelectOrder.se lectedIndex == -1 ) return;

document.forms[0].UpButton.disab led =
document.forms[0].DownButton.dis abled = true;

if ( document.forms[0].SelectOrder.se lectedIndex>0)
{
var selIndex = document.forms[0].SelectOrder.se lectedIndex;
var text = document.forms[0].SelectOrder.op tions[ selIndex ].text;
var value = document.forms[0].SelectOrder.op tions[ selIndex ].value;
document.forms[0].SelectOrder.op tions[ selIndex ].text =
document.forms[0].SelectOrder.op tions[ selIndex -1].text;
document.forms[0].SelectOrder.op tions[selIndex ].value =
document.forms[0].SelectOrder.op tions[ selIndex -1].value;
document.forms[0].SelectOrder.op tions[ selIndex -1].text = text;
document.forms[0].SelectOrder.op tions[ selIndex -1].value = value;

document.forms[0].SelectOrder.se lectedIndex--;
}
document.forms[0].UpButton.disab led =
document.forms[0].DownButton.dis abled = false;
}

function GenerateIDsSubm it()
{

//see the order of the select and set
var s= new String();
for( var i=0; i< document.forms[0].SelectOrder.op tions.length; i++)
s=s + "," + document.forms[0].SelectOrder.op tions[i].value;
document.forms[0].userIDs.value = s.slice(1, s.length);
document.all["GetStatsBT N"].click();

}

</script>

<input type="button" value="Send" onclick="Genera teIDsSubmit();" >

<input type="button" id="UpButton" name="UpButton" value="Up"
onclick="GoUp() ;"><br>
<input type="button" id="DownButton " name="DownButto n" value="Down"
onclick="GoDown ();">
<select id="SelectOrder " size=10 name="SelectOrd er"></select>

"CodeRazor" <Co*******@disc ussions.microso ft.com> wrote in message
news:74******** *************** ***********@mic rosoft.com...
Is it possible to reorder items in a listbox server control by having the
user select an item and then click an up or down button? ... how?
Or is this something that can only be achieved client side?

thanks


Nov 17 '05 #3
no problem,

just let me know if it solved your problem

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"CodeRazor" <Co*******@disc ussions.microso ft.com> wrote in message
news:75******** *************** ***********@mic rosoft.com...
thank you

"Ignacio Machin ( .NET/ C# MVP )" wrote:
hi,

of course it's possible and yes, you should do it in client side,
otherwise
you would get a lot of roundtrip
find the code below for doing just that
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

<script>
function GoDown()
{
if ( document.forms[0].SelectOrder.se lectedIndex == -1 ) return;
document.forms[0].UpButton.disab led =
document.forms[0].DownButton.dis abled = true;

if ( document.forms[0].SelectOrder.se lectedIndex<
document.forms[0].SelectOrder.op tions.length-1)
{
var selIndex = document.forms[0].SelectOrder.se lectedIndex;
var text = document.forms[0].SelectOrder.op tions[ selIndex ].text;
var value = document.forms[0].SelectOrder.op tions[ selIndex ].value;
document.forms[0].SelectOrder.op tions[ selIndex ].text =
document.forms[0].SelectOrder.op tions[ selIndex +1].text;
document.forms[0].SelectOrder.op tions[selIndex ].value =
document.forms[0].SelectOrder.op tions[ selIndex +1].value;
document.forms[0].SelectOrder.op tions[ selIndex +1].text = text;
document.forms[0].SelectOrder.op tions[ selIndex +1].value = value;

document.forms[0].SelectOrder.se lectedIndex++;
}
document.forms[0].UpButton.disab led =
document.forms[0].DownButton.dis abled = false;
}

function GoUp()
{
if ( document.forms[0].SelectOrder.se lectedIndex == -1 ) return;

document.forms[0].UpButton.disab led =
document.forms[0].DownButton.dis abled = true;

if ( document.forms[0].SelectOrder.se lectedIndex>0)
{
var selIndex = document.forms[0].SelectOrder.se lectedIndex;
var text = document.forms[0].SelectOrder.op tions[ selIndex ].text;
var value = document.forms[0].SelectOrder.op tions[ selIndex ].value;
document.forms[0].SelectOrder.op tions[ selIndex ].text =
document.forms[0].SelectOrder.op tions[ selIndex -1].text;
document.forms[0].SelectOrder.op tions[selIndex ].value =
document.forms[0].SelectOrder.op tions[ selIndex -1].value;
document.forms[0].SelectOrder.op tions[ selIndex -1].text = text;
document.forms[0].SelectOrder.op tions[ selIndex -1].value = value;

document.forms[0].SelectOrder.se lectedIndex--;
}
document.forms[0].UpButton.disab led =
document.forms[0].DownButton.dis abled = false;
}

function GenerateIDsSubm it()
{

//see the order of the select and set
var s= new String();
for( var i=0; i< document.forms[0].SelectOrder.op tions.length; i++)
s=s + "," + document.forms[0].SelectOrder.op tions[i].value;
document.forms[0].userIDs.value = s.slice(1, s.length);
document.all["GetStatsBT N"].click();

}

</script>

<input type="button" value="Send" onclick="Genera teIDsSubmit();" >

<input type="button" id="UpButton" name="UpButton" value="Up"
onclick="GoUp() ;"><br>
<input type="button" id="DownButton " name="DownButto n" value="Down"
onclick="GoDown ();">
<select id="SelectOrder " size=10 name="SelectOrd er"></select>

"CodeRazor" <Co*******@disc ussions.microso ft.com> wrote in message
news:74******** *************** ***********@mic rosoft.com...
> Is it possible to reorder items in a listbox server control by having
> the
> user select an item and then click an up or down button? ... how?
> Or is this something that can only be achieved client side?
>
> thanks


Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2511
by: Grant Schenck | last post by:
Hello, I have a ListBox control on a form. I add members of a class to the Items collection. They show up and I can select them. The text shown is from my classes ToString override. Now, later on I need to update this item. I find it in the Items collection and update a member used by the ToString member function. However, the text shown for the item in the ListBox does not change.
1
2276
by: yamne | last post by:
I have a problem. When I click in edit datagrid button I show two listbox and two button. I use two button to move data between two listbox. My problem is that I can't call the listbox in the button_click function because the only way to find the listbox is: (listbox)e.item.findcontrol What s the solution to this problem?
7
10072
by: 00_ChInkPoIntD12 | last post by:
Can anyone confirm there isn't a Sort() method for WebControl Listbox in Asp.net? It is rather simple to write a method to do the sorting, but just wondering I shouldn't invent the wheel if there is already one. C.P.
2
3848
by: tangokilo | last post by:
Hello and thanks for your help, I have the following Listbox created in VisualStudio 2003 designer, desiring to select multiple entries from that list: ------------------------------- ListBoxUser.Location = New System.Drawing.Point(16, 240) ListBoxUser.Name = "ListBoxUser" ListBoxUser.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended ListBoxUser.Size = New System.Drawing.Size(136, 147) ListBoxUser.TabIndex = 6
3
2304
by: Ali Chambers | last post by:
Hi, I have created a listbox called "dtlist1" on my VB.NET form. I call a procedure as follows: Private Sub openfile(flname As String) dtlist1.Items.Clear() etc..
0
1016
by: K B | last post by:
I'm using ASP.NET 2.0 and am still struggling. I use the following code to reorder items in a listbox. When complete, a Save button saves each item to a database. Works fine for the first click (runat=Server) but on subsequent use the item just seems to go anywhere...usually to the top of the list. PLEASE, how can I accomplish this using a listbox control and code (not javascript)? Dim mSelectedIndex, mOtherIndex As Integer
4
4969
by: rn5a | last post by:
Can the items in a ListBox be sorted by the name of the items? The ListBox actually lists all directories & files existing in a directory on the server. Note that all the directories should be listed first followed by the files.
4
6130
by: rdraider | last post by:
Use the Northwind database Products table as an example. Purchasing dept gets a report showing when inventory items on hand qty are below the reorder level. easy enough: Select ProductID, ProductName, SupplierID, UnitsInStock, ReorderLevel from Products where (UnitsInStock < ReorderLevel) Results: ProductID ProductName SupplierID UnitsInStock ReorderLevel
1
4035
by: Sunray | last post by:
I have a form called the sales form and i have 2 sets of listboxes So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which are not bound, I select from the bottom set and add to the top set which works fine, but now i decide to remove an item from the top set. when i tried to use a remove item code it worked fine, it did delete the item form the list but it added...
0
9886
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10983
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10647
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10706
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7882
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5911
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4528
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4119
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3164
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.