473,473 Members | 2,193 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

List Control, multiple choise from the code

Hello!

Please, could anyone tell, is it possible to set multiple items to be
selected in list control in the code? For example when the web form is loaded
three items of 5 are selected in list control already? Now I manage to set
only one item to be selected during page load, but there is need to multiple
items could be selected for the user. I appreciate very much your help!

Thanks.

Pavel
Nov 18 '05 #1
2 2252
Peter wrote:
Hello!

Please, could anyone tell, is it possible to set multiple items to be
selected in list control in the code? For example when the web form is loaded
three items of 5 are selected in list control already? Now I manage to set
only one item to be selected during page load, but there is need to multiple
items could be selected for the user. I appreciate very much your help!

Thanks.

Pavel

Yes, try this statement before you start selecting the items

'Set Selection mode as Multiple
[YourListBoxID].SelectionMode = ListSelectionMode.Multiple

Full Page Example:
------------------
<%@ PAGE language="VB" runat="server" %>

<SCRIPT language="vb" runat="server">

Sub Page_Load(Source as Object, E As EventArgs)

'Add Items To List
lbxList.Items.Add("Item 1")
lbxList.Items.Add("Item 2")
lbxList.Items.Add("Item 3")
lbxList.Items.Add("Item 4")
lbxList.Items.Add("Item 5")
lbxList.Items.Add("Item 6")
lbxList.Items.Add("Item 7")
lbxList.Items.Add("Item 8")
lbxList.Items.Add("Item 9")
lbxList.Items.Add("Item 10")

lbxList.Rows = 10
'Set Selection mode as Multiple
lbxList.SelectionMode = ListSelectionMode.Multiple

Dim litmItem as ListItem

' Select every third list item
Dim i As Integer = 0

For Each litmItem In lbxList.Items
If (i + 1) MOD 3 = 0 Then
litmItem.Selected = True
End If
i += 1
Next

End Sub
</SCRIPT>

<HTML>
<HEAD>
<TITLE>Multi-Selected ListBox</TITLE>
</HEAD>
<BODY>
<FORM id="theForm" runat="server">
<ASP:listbox id="lbxList" runat="server"/>

</FORM>
</BODY>
</HTML>
--
Change "seven" to a digit to email.
Nov 18 '05 #2
Hi

jus try this,

lstdropdown.SelectedIndex = -1;
for (int i=0; i<Datatable.Rows.Count;i++)

lstdropdown.Items.FindByValue(Datatable.Rows[i]["ColumnName"].ToString()).Se
lected=true;

Regards,
Kannan

"Peter" <Pe***@discussions.microsoft.com> wrote in message
news:DB**********************************@microsof t.com...
Hello!

Please, could anyone tell, is it possible to set multiple items to be
selected in list control in the code? For example when the web form is loaded three items of 5 are selected in list control already? Now I manage to set
only one item to be selected during page load, but there is need to multiple items could be selected for the user. I appreciate very much your help!

Thanks.

Pavel

Nov 18 '05 #3

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

Similar topics

1
by: Polar | last post by:
I have a listbox with 5 options. I have set it up to be able to choise more than one option. What I need to know is how to get all the selection into the one string that is stored in the DB ...
0
by: Boris F | last post by:
Problem in DotNet 2003. I have CrystalReport Class in my project. When I'm trying to create instance of ReportDocument control on my form in IDE dialog box comes up with multiple choise of...
2
by: Wysiwyg | last post by:
I was hoping to get some opinions on the efficiency of various methods of reusing the same dropdown list data. Here is the situation: Multiple panels on maintenance pages with TAB menus across...
2
by: bienwell | last post by:
Hi all, I've got a problem with getting the data values from multiple selections in the list box. I could only get the value and the index of the first item from the selection, but not the...
1
by: Samuel Shulman | last post by:
In VB.NET I made an extensive use of the ListView Control I am new to ASP.NET and I wonder what is the best control to use, I noticed that the GridControl is not as flexible as (AFAIK) it is...
4
Rabbit
by: Rabbit | last post by:
Cascading Combo/List Boxes This tutorial is to guide you in the creation of Cascading combo/list boxes. That is when you have multiple combo/list boxes where the selection of an option in one...
2
by: kietto | last post by:
Hi everybody i'm new to bytes.com and also python programming :-) Can somebody point me in the right direction or suggest me a good way to do this..? The software i'd like to write is a kind of...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
1
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
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
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.