467,219 Members | 1,228 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,219 developers. It's quick & easy.

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
  • viewed: 2023
Share:
2 Replies
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Polar | last post: by
reply views Thread by Boris F | last post: by
1 post views Thread by Samuel Shulman | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.