|
-
Oct 2nd, 2008, 11:23 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] [2005] Set selected listbox items programmatically
Hi,
I'm trying to set up a multiple select list boxes selected items, but it's only displaying the last item. Does anyone know how to do this?
This is what I have -
vb Code:
...
Dim sSSect_Ids As String = clAct.DeNull(dr("SSection_Ids"))
If sSSect_Ids <> vbNullString Then
Dim sVals() As String = sSSect_Ids.Split(",".ToCharArray)
Dim i As Int32 = -1
Dim uBnd As Int32 = UBound(sVals)
For i = 0 To uBnd
sVals(i) = clAct.DeNull(sVals(i).Trim)
If sVals(i) <> vbNullString Then
Me.ddlSSection.SelectedValue = Convert.ToString(sVals(i))
End If
Next
End If
...
Al
-
Oct 3rd, 2008, 02:50 AM
#2
Thread Starter
Fanatic Member
Re: [2005] Set selected listbox items programmatically
I've managed to solve it, using .Items.FindByValue(s) and item(s).Selected=True -
vb Code:
Dim sSSect_Ids As String = clAct.DeNull(dr("SSection_Ids"))
If sSSect_Ids <> vbNullString Then
Dim sVals() As String = sSSect_Ids.Split(",".ToCharArray)
Dim i As Int32 = -1
Dim uBnd As Int32 = UBound(sVals)
For i = 0 To uBnd
sVals(i) = clAct.DeNull(sVals(i).Trim)
If sVals(i) <> vbNullString Then
sVals(i) = Convert.ToString(sVals(i))
If Not Me.ddlSSection.Items.FindByValue(sVals(i).ToString) Is Nothing Then
Me.ddlSSection.Items(sVals(i).ToString).Selected = True
End If
End If
Next
End If
-
Oct 6th, 2008, 05:14 AM
#3
Re: [RESOLVED] [2005] Set selected listbox items programmatically
Use the ASP.NET Listbox control. To read the selected items, use
vb Code:
For i = 0 to ListBox1.Items.Count If ListBox1.Items(i).Selected = True Then 'Do something with ListBox1.Items(i) End If Next i
-
Oct 6th, 2008, 05:55 AM
#4
Thread Starter
Fanatic Member
Re: [RESOLVED] [2005] Set selected listbox items programmatically
Mendhak,
Thanks for your reply, I'm not sure but think there might be a slight misunderstanding with my question. Your suggestion is exactly what I'm using to save the users selections to my DB. I was having trouble setting the default items (the items chosen previously) when a user edits a record
If you have a better way of achieving this then I'd be delighted to see it
Cheers Al
-
Oct 6th, 2008, 07:56 AM
#5
Re: [RESOLVED] [2005] Set selected listbox items programmatically
Ah yeah, your first post was a bit vague, so I jumped to the most common problem encountered with listboxes.
Your method is fine then, because all you need is some way to persist the values across postbacks or from elsewhere.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|