Multiselect List Box

  • Thread starter Thread starter Steph
  • Start date Start date
S

Steph

I have created a multiselect list box control (lbx_comorb) that is
populated from a datatable (dt_ptAdmission). The list box populates
now problem at all.

However the issue is when I load the webform, when there is already
admission data. I need the populated list box (lbx_comorb) to show the
items that were previously selected for this admission. The selected
comorb data is stored in another datatable (dt_ptComorb).

If anyone can help with this it'd be greatly appreciated.

Cheers
 
Hi Steph,
Each Item in the ListBox has a Selected property, so loop through the
items you want to show as selected, and set the Selected property of
the corresponding ListBox item to True.

Marcie
 
Hi Marcie

Thanks for the quick response. I am just wondering how I would do
this.

Code to populate the list box is as follows:
Note: I am doing it this was as I have to load data for 20 different
drop down lists.

Dim objConn As New SqlConnection(strCS)
Dim objDS As New DataSet
Dim objDA As New SqlDataAdapter

Dim objCommand As New SqlCommand
objDA.SelectCommand = objCommand
objCommand.Connection = objConn
objCommand.CommandType = CommandType.Text

'Load Comorbidities details to list box
objCommand.CommandText = "usp_ref_Comorb"
objDA.Fill(objDS, "tbl_Clinical_Comorb")
Me.lbx_Comorb.DataSource = objDS
Me.lbx_Comorb.DataMember = "tbl_Comorb"
Me.lbx_Comorb.DataTextField = "ReferenceDescription"
Me.lbx_Comorb.DataValueField = "ReferenceID"
Me.lbx_Comorb.DataBind()
Me.lbx_Comorb.Items.FindByText("None").Selected = True

'Load Patient Comorbidities to datatable
objCommand.CommandText = "usp_Admis_Comorb '" & strAdmissionID & "'"
objDA.Fill(objDS, "dt_ptComorb")

'Load Seleceted values into comorb ListBox
If objDS.Tables("dt_ptComorb").Rows(0)("ComorbID").GetType.ToString <>
"System.DBNull" Then
Me.lbx_Comorb.Items.FindByValue(dt.Rows(0)("ComorbID")).Selected
= True
End If

I'm not 100% sure how to loop through all the rows from the datatable
(dt_ptcomorb) to show the multiple selected values in the listbox.

Thanks again for your assistance
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top