473,397 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

2 listbox(html control) and javascript between them

Hi all,
i m transefering values from one listbox to another listbox using
javascript(both are html controls), the first listbox is populating with
database at page_load time and the second listbox is empty initially .the two
buttons which i have taken are both(btnAd,btnRemove) have values Add,Remove
and both are input type with run as server control property set to true,.my
script is given below , however when i click on add button the items go to
another listbox but disaapears at the same moment ,, i dont know what is the
reason.. plz help me ....should i change the script or what ...if possible
kindly help me with new script or entire solution.. my sincere thanks in
advance.. i want to remove the items from the other listbox also on clicking
remove buton using javascipt...i want to set multiple selection property true
in both listboxes also. also when i add to second list box then i have to
insert the values of items to database table also and on removeing it should
remove from listbox and from database table(i.e. those values) also ,.
------------------------------------------------------------------------------------------------
function doDetail(Action)
{
switch(Action)
{
case 'Add':
var lstFrom = document.getElementById("lstFrom");
var lstTo = document.getElementById("lstTo");
if(document.Form1.lstFrom.selectedIndex == -1)
{
alert('Please select atleast one record to Add');
return;
}
else
{
var selIndex = lstFrom.selectedIndex;
var optionText = lstFrom.options[selIndex].text;
var optionVal = lstFrom.options[selIndex].value;
var optionIndex = lstTo.options.length;
var objOption = new Option(optionText, optionVal);
lstTo.options[optionIndex] = objOption;
lstFrom.options[selIndex] = null;
}
break;

case 'Remove':
var lstFrom = document.getElementById("lstTo");
var lstTo = document.getElementById("lstFrom");
if(document.Form1.lstFrom.selectedIndex == -1)
{
alert('Please select atleast one record to Remove');
return;
}
else
{
var selIndex = lstFrom.selectedIndex;
var optionText = lstFrom.options[selIndex].text;
var optionVal = lstFrom.options[selIndex].value;
var optionIndex = lstTo.options.length;
var objOption = new Option(optionText, optionVal);
lstTo.options[optionIndex] = objOption;
lstFrom.options[selIndex] = null;
}
break;

}
}
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
'Button1.Attributes("OnClick") = "javascript:AddVals()"
'Button2.Attributes("OnClick") = "javascript:RemVals()"

btnAdd.Attributes("OnClick") = "javascript:doDetail(this.value);"
btnRemove.Attributes("OnClick") = "javascript:doDetail(this.value);"
If Page.IsPostBack = False Then
fnFillListBox()

End If
End Sub
Public Sub fnFillListBox()
Dim strDatabaseId, strDatabaseName As String

Dim sql As String = "select DatabaseName,DatabaseID from mstDatabase"
Conn = New SqlConnection(connstr)
Conn.Open()
Cmd = New SqlCommand(sql, Conn)
dtrdr = Cmd.ExecuteReader
dtrdr.Read()
lstFrom.DataSource = dtrdr
lstFrom.DataTextField = "DatabaseName"
lstFrom.DataValueField = "DatabaseID"
lstFrom.DataBind()
dtrdr.Close()
Cmd.Dispose()
Conn.Close()
Conn.Dispose()
End Sub
------------------------------------------------------------------------------------------------
Nov 19 '05 #1
0 1565

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

Similar topics

2
by: Ben | last post by:
I've got an asp page that populates a listbox with info from a db. The list box ends up being pretty big, so I want to be able to search it effectively. I like the method wherein the user types...
0
by: CoreyMas | last post by:
Hello everyone Is there a way to create a double click event on a listbox control in VB.net without having to resort to Javascript? Thanks in advance Corey
5
by: Brian | last post by:
Hi, All, I'm using MS.net 2003 and using a windows.forms.listbox control for my window application but I don't know why the Horizontal Scrollbar could NOT be shown even if I set...
4
by: Hardy Wang | last post by:
Hi I have a ListBox control in my ASP.NET page. After I binding data to this control, I would like to be able to change this display order of items in this control. Just like change layout...
4
by: Moe Sizlak | last post by:
Hi There, I am trying to return the value of a listbox control that is included as a user control, I can return the name of the control but I can't access the integer value of the selected item,...
6
by: msnews.microsoft.com | last post by:
Hi All, I am creating a control with ASP "ListBox" control. Also I have added necessary code to handle the ListBox.SelectedItemChanged Event. But surprisingly the control is not comng to...
5
by: Zack Sessions | last post by:
Using VB.NET. I have a ListBox control that I have populated with a list of items. The user selects one or more items from the list to process. The best way I have found to loop through the...
7
by: Dave | last post by:
Hi all, After unsuccessfully trying to make my own dual listbox control out of arraylists, I decided to look for a 3rd party control. I've looked for over a week now and can't find anything but...
3
by: Hugh O | last post by:
Hi, There is a ROW property on the Web Listbox control within VB.Net. The description states it is "The number of visible rows to display". I have tried setting this property in many different...
4
by: kimiraikkonen | last post by:
Hi, I have a odd but a known question about listbox. I know listbox control can provide multi-select, multi-extendend selections. But i wonder if this selection type belongs to them or it has...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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,...
0
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...
0
tracyyun
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...
0
agi2029
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,...
0
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...

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.