tôi có hai hộp danh sách (listbox 1 và listbox2) .i đã sử dụng mã javscript sau để di chuyển giá trị từ một hộp danh sách sang khác.di chuyển giá trị từ một hộp danh sách sang sử dụng javascript khác và sau đó đọc giá trị bằng cách sử dụng C#
<script language="javascript" type="text/javascript">
function fnMoveItems(lstbxFrom,lstbxTo)
{
var varFromBox = document.all(lstbxFrom);
var varToBox = document.all(lstbxTo);
if ((varFromBox != null) && (varToBox != null))
{
if(varFromBox.length < 1)
{
alert('There are no items in the source ListBox');
return false;
}
if(varFromBox.options.selectedIndex == -1) // when no Item is selected the index will be -1
{
alert('Please select an Item to move');
return false;
}
while (varFromBox.options.selectedIndex >= 0)
{
var newOption = new Option(); // Create a new instance of ListItem
newOption.text = varFromBox.options[varFromBox.options.selectedIndex].text;
newOption.value = varFromBox.options[varFromBox.options.selectedIndex].value;
varToBox.options[varToBox.length] = newOption; //Append the item in Target Listbox
varFromBox.remove(varFromBox.options.selectedIndex); //Remove the item from Source Listbox
}
}
return false;
}
</script>
Mã này chuyển giá trị từ một listbox khác, nhưng thực sự khi tôi cố gắng để đọc các giá trị listbox thứ hai, từ một đến whhich giá trị được sao chép, tôi không thể đọc những giá trị đó. khi tôi kiểm tra nó cho thấy ListBox2.Items.Count
là 0
Không chắc chắn nhưng, có trạng thái xem được kết hợp với điều khiển asp.net, vì bạn đang thêm các mục trên phía máy khách, nó có thể không phản ánh trên máy chủ. Bất cứ ai vui lòng sửa nếu tôi sai. –
Có thể điều này có thể giúp: http://extendedlistbox.codeplex.com/. Nó thay thế trên bay một hộp danh sách html với hai danh sách thả xuống, với các nút để di chuyển giữa các twos. Từ phía máy chủ, thật dễ dàng để thao tác khi bạn làm việc với một hộp danh sách đơn giản với nhiều lựa chọn. ** Disclaimer ** Tôi là người tạo ra dự án –
Đây là một cách để thực hiện: http://www.dotnet-developer.de/2008/07/aspnet2005/ajax/using-javascript-on-listboxes-in -aspnet / – keyboardP