472,337 Members | 1,207 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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 2195
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...
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...
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...
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...
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...
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...
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...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

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.