Manually Ordering Elements within a Listbox
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngfreeforall' list.


Eric Marthinsen
Hello-

    I have a listbox that lists fields in a database. On my aspx
page, I want an up arrow button and a down arrow button. If a user
selects an item in the listbox and presses the up arrow, then that item
moves up the listbox order, the opposite for the down arrow. What is
the best way to create this functionality in ASP.NET? My thought was
that I'd just create some client-side javascript that manipulated the
listbox (whose I'd I'll already know), but this is a mix of server and
client-side functionaliy that feels a bit like a hack. Is there a
better, more encapsulated way to so this? I don't want to do any
round-trips, so server-side processing so postbacks aren't an option.

Regards-
    Eric

Reply to this message...
 
    
Bill Swartz
Hi Eric,

Without a round trip to the server, you must implement this functionality in
javaScript. Your button would have an onclick attribute that would execute
a client side javascript function that would change the index of the
listbox.

You can do this a couple of ways.

For dynamically created forms, add the attribute dynamically.
<< Not a javaScript expert, so this code might not work >>
btnUpArrow.Attributes.Add("onclick", "moveIndex("+1")");
btnDnArrow.Attributes.Add("onclick", "moveIndex("-1")");

Or directly in the htmlTag

<asp:LinkButton id="btnUpArrow" runat="server"
onClick="javascript:moveIndex('+1');"

hth,
Bill

-----Original Message-----
From: Eric Marthinsen [mailto:Click here to reveal e-mail address]
Sent: Sunday, August 18, 2002 2:28 PM
To: aspngfreeforall
Subject: [aspngfreeforall] Manually Ordering Elements within a Listbox

Hello-

    I have a listbox that lists fields in a database. On my aspx
page, I want an up arrow button and a down arrow button. If a user
selects an item in the listbox and presses the up arrow, then that item
moves up the listbox order, the opposite for the down arrow. What is
the best way to create this functionality in ASP.NET? My thought was
that I'd just create some client-side javascript that manipulated the
listbox (whose I'd I'll already know), but this is a mix of server and
client-side functionaliy that feels a bit like a hack. Is there a
better, more encapsulated way to so this? I don't want to do any
round-trips, so server-side processing so postbacks aren't an option.

Regards-
    Eric

| ASP.net DOCS = http://www.aspng.com/docs
| [aspngfreeforall] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/aspngfreeforall = JOIN/QUIT
| news://ls.asplists.com = NEWSGROUP

Reply to this message...
 
    
Andrew Zetterman
I've used this method a few times....

http://www.mattkruse.com/javascript/selectbox/index.html

-----Original Message-----
From: Bill Swartz [mailto:Click here to reveal e-mail address]=20
Sent: Sunday, August 18, 2002 7:00 PM
To: aspngfreeforall
Subject: [aspngfreeforall] RE: Manually Ordering Elements within a
Listbox

Hi Eric,

Without a round trip to the server, you must implement this
functionality in javaScript. Your button would have an onclick
attribute that would execute a client side javascript function that
would change the index of the listbox.

You can do this a couple of ways.

For dynamically created forms, add the attribute dynamically. << Not a
javaScript expert, so this code might not work >>
btnUpArrow.Attributes.Add("onclick", "moveIndex("+1")");
btnDnArrow.Attributes.Add("onclick", "moveIndex("-1")");

Or directly in the htmlTag

<asp:LinkButton id=3D"btnUpArrow" runat=3D"server"
onClick=3D"javascript:moveIndex('+1');"

hth,
Bill

-----Original Message-----
From: Eric Marthinsen [mailto:Click here to reveal e-mail address]
Sent: Sunday, August 18, 2002 2:28 PM
To: aspngfreeforall
Subject: [aspngfreeforall] Manually Ordering Elements within a Listbox

Hello-

    I have a listbox that lists fields in a database. On my aspx
page, I want an up arrow button and a down arrow button. If a user
selects an item in the listbox and presses the up arrow, then that item
moves up the listbox order, the opposite for the down arrow. What is
the best way to create this functionality in ASP.NET? My thought was
that I'd just create some client-side javascript that manipulated the
listbox (whose I'd I'll already know), but this is a mix of server and
client-side functionaliy that feels a bit like a hack. Is there a
better, more encapsulated way to so this? I don't want to do any
round-trips, so server-side processing so postbacks aren't an option.

Regards-
    Eric

| ASP.net DOCS =3D http://www.aspng.com/docs
| [aspngfreeforall] member Click here to reveal e-mail address =3D YOUR ID=20
| http://www.asplists.com/aspngfreeforall =3D JOIN/QUIT=20
| news://ls.asplists.com =3D NEWSGROUP

| ASP.net DOCS =3D http://www.aspng.com/docs
| [aspngfreeforall] member Click here to reveal e-mail address =3D YOUR ID=20
| http://www.asplists.com/aspngfreeforall =3D JOIN/QUIT=20
| news://ls.asplists.com =3D NEWSGROUP

Reply to this message...
 
 
System.Web.UI.WebControls.LinkButton




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com