I have a web form which has a multiple select dropdown list. The dropdown data is bound from a table. On submission the selected items are pushed to an mssql table.
I have an edit version of the form where the various data is read into the form allowing the user to edit the fields and resubmit the form.
I want the multiple select drowdown to have the currently stored selections highlighted.
I have working code:
While the above code works where the goindex corresponds to the correct record. The bound table is sorted by primary key where the primary key sort order is the same as the current index.
As an example in the table facilityid 1 is for Apple, and facilityid 2 if for Pear, facilityid 3 is for Orange and so on.
When I sort the bound table by the facilityid (Primary Key) the list items are sorted Apple, Pear, Orange and so on... Their facilityid is the same as the index of the listbox, so the above code preselects the correct list items.
However...
If the bound table is sorted, say by Alpha, the the sort order is Apple, Orange, Pear and so on... Now the facilityid (Primary Key) does not match the current index of the listobox, so the incorrect list items are selected.
Is there a way to bind or set the index of a listbox to the primary key or index of a table? So if for instance record 4 has been deleted and the sort order is now 1, 2, 3, 5, is it possible to set the index of the listbox to be 1, 2, 3, 5?
I intitialy wanted to loop through the data set and match the text value of the record with the list item text value, using the following code within the datareader.
That only returns the last list item.
I am using a Windows 2008 server, MS SQL, Visual Studio 2008 and writing in VB.Net.
Any thoughts or suggestions?
tia... mike
I have an edit version of the form where the various data is read into the form allowing the user to edit the fields and resubmit the form.
I want the multiple select drowdown to have the currently stored selections highlighted.
I have working code:
Code:
While MyDataReader.Read
Dim goindex As Integer
goindex = MyDataReader("facilityid")
goindex = goindex - 1
facilityidlist.Items(goindex).Selected = True
End While
While the above code works where the goindex corresponds to the correct record. The bound table is sorted by primary key where the primary key sort order is the same as the current index.
As an example in the table facilityid 1 is for Apple, and facilityid 2 if for Pear, facilityid 3 is for Orange and so on.
When I sort the bound table by the facilityid (Primary Key) the list items are sorted Apple, Pear, Orange and so on... Their facilityid is the same as the index of the listbox, so the above code preselects the correct list items.
However...
If the bound table is sorted, say by Alpha, the the sort order is Apple, Orange, Pear and so on... Now the facilityid (Primary Key) does not match the current index of the listobox, so the incorrect list items are selected.
Is there a way to bind or set the index of a listbox to the primary key or index of a table? So if for instance record 4 has been deleted and the sort order is now 1, 2, 3, 5, is it possible to set the index of the listbox to be 1, 2, 3, 5?
I intitialy wanted to loop through the data set and match the text value of the record with the list item text value, using the following code within the datareader.
Code:
facilityidlist.SelectedValue = Convert.ToString(facilityidlist.Items.FindByText(MyDataReader("facilityname")).Value)
That only returns the last list item.
I am using a Windows 2008 server, MS SQL, Visual Studio 2008 and writing in VB.Net.
Any thoughts or suggestions?
tia... mike