Hello,
I used the below code to move selected items between two listboxes
Left and Right:-
<%@ Page Language="C#" AutoEventWireup ="true"
CodeFile="TestP opup.aspx.cs" Inherits="TestP opup" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitl ed Page</title>
<script type="text/javascript">
/*
- Function MoveItems()
- Direction: Specifies direction i.e. L = Left, R = Right
- All: Move All items 1 = All, 0 = Selected
*/
function MoveItems(Direc tion, All)
{
var LstLeft;
var LstRight;
var Removed = '';
var i;
if (Direction == 'R')
{
var LstLeft = document.getEle mentById("<
%=LstLeft.Clien tID %>");
var LstRight = document.getEle mentById("<
%=LstRight.Clie ntID %>");
}
else
{
var LstLeft = document.getEle mentById("<
%=LstRight.Clie ntID %>");
var LstRight = document.getEle mentById("<
%=LstLeft.Clien tID %>");
}
for (i=0; i<LstLeft.lengt h; i++)
{
if (LstLeft.option s[i].selected || All == 1)
if(ItemExists(L stRight, LstLeft.options[i].value)
== 0)
{
LstRight[LstRight.length] = new
Option(LstLeft. options[i].text, LstLeft.options[i].value, true);
Removed = Removed + LstLeft.options[i].value +
',';
}
}
RemoveFromList( LstLeft, Removed);
return false;
}
function RemoveFromList (Lst, Items)
{
var Removed = Items.split(',' );
var j;
var x;
for (j=0; j<Removed.lengt h; j++)
{
for (x=0; x<Lst.length; x++)
{
if (Lst.options[x] != null && Lst.options[x].value
== Removed[j])
{
Lst.options[x] = null;
}
}
}
}
function ItemExists(Lst, value)
{
var Flag = 0;
var i = 0;
for (i=0; i<Lst.length; i++)
{
if (Lst.options[i].value == value)
{
Flag = 1;
break;
}
}
return Flag;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ListBox ID="LstLeft" runat="server"
SelectionMode=" multiple" Width="200px" Rows="5" >
<asp:ListItem Value="0" Text="Farhan"></asp:ListItem>
<asp:ListItem Value="1" Text="Moin"></asp:ListItem>
<asp:ListItem Value="2" Text="Haroon"></asp:ListItem>
<asp:ListItem Value="3" Text="Khurram"> </asp:ListItem>
<asp:ListItem Value="4" Text="Mansur"></asp:ListItem>
</asp:ListBox>
<asp:ListBox ID="LstRight" runat="server"
SelectionMode=" multiple" Width="200px" Rows="5">
</asp:ListBox>
<br />
<asp:Button ID="BtnRight" runat="server" Text=">"
OnClientClick=" return MoveItems('R', 0);" />
<asp:Button ID="BtnLeft" runat="server" Text="<"
OnClientClick=" return MoveItems('L', 0);"/>
<asp:Button ID="BtnRightAll " runat="server" Text=">>"
OnClientClick=" return MoveItems('R', 1);" />
<asp:Button ID="BtnLeftAll " runat="server" Text="<<"
OnClientClick=" return MoveItems('L', 1);" />
</div>
</form>
</body>
</html>
Problem:-
I am unable to retrieve the items of the listbox on postback which are
filled using the javascipt code as shown above.
I am able to retrieve all the other fields values on postback , but
these two listboxes don't show the updated count and items list.The
rightbox items count on postback is zero though the items are moved
into it from the left listbox.
I am using EnableEventVali dation="false" .
Please help me with how to retrieve the updated listbox items on
postback.
Thanks ,
Divya 1 3687
Hi divya.
I am not sure about what went wrong. please try the bellow
technique...
Please use a hidden input field in your page, while moving the items
in right listbox in javascript
save the itemvalues in a comma or semicolon separated way in the
hidden field.
After postback, In "Page_load" event check the hidden input's value,
and modify both list box ....
Best of luck
Munna www.munna.shatkotha.com www.munna.shatkotha.com/blog www.shatkotha.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Edward |
last post by:
I am having a terrible time getting anything useful out of a listbox
on my web form.
I am populating it with the results from Postcode lookup software, and
it is showing the results fine. What I want to do is to allow the
user to click on the row that corresponds to the correct address, and
have the code behind populate the form's Address1, Address2 etc.
controls with the relevant data items.
I put the code for this into the...
|
by: Valerian John |
last post by:
I have a ListBox webcontrol on an aspx page. Items are added to the
ListBox using client-side code. However, when the page is posted back the
items are missing/not available. (It is like the page does not know the
items were added client-side.)
TIA,
Val
|
by: Stimp |
last post by:
I have a listbox of values that I populate from a database.
I want the user to be able to re-order the list
(by first selecting an item and then clicking 'up' or 'down' buttons)
and then save the list back to the database.
First of all, I implemented the re-ordering through client-side
javascript, which worked great (also it didn't require a postback every
time an item was re-ordered). For testing purposes, I'm outputting the
contents...
|
by: Ohad Asor |
last post by:
Hello all,
I have an ASP.NET page I've written using VS.NET2003, which have a ListBox
in it. When I press a button in the form, I try to get the selected item in
the list by calling ListBox.SelectedItem. And it returns null, even when I
select an item.
Even when I try to read the value when I get the SelectedIndexChanged event,
it still doesn't give me the correct answer.
|
by: Adam Clauss |
last post by:
I have a page containing a list box. This list may contain duplicate
items - in which the ORDER is important.
ex:
a
b
b
a
is significant as compared to:
b
| |
by: zdrakec |
last post by:
Hello all:
Clearly, I'm not getting it! Here is the scenario:
On a web page, I have two list boxen and a text box. The first listbox
is populated at page load time (if it is not a postback). This listbox
has AutoPostback = True. When the user selects an item from this list,
the second listbox is populated with more items relevant to this
selection. I am using an SQLDataSource web control for this. These
items are headers. I want, when...
|
by: Lit |
last post by:
Hi,
How can I capture the vertical scroll bar position for a Listbox.
I have a Listbox of 100 items + when I click on it I post back remove the
item selected.
After returning to the client browser the list box scroll position is at the
top.
|
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...
|
by: bogdan |
last post by:
Hi,
I have two listboxes on a page and need to move items between them - using
buttons (e.g. "<<" ">>"). Can this be done on a client side in asp.net?
I'd like to avoid hitting the server on every add/remove.
Thanks,
Bogdan
|
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...
|
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...
| |
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,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
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...
| | |