Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listbox Multiple Selection Update Record

Status
Not open for further replies.

BrendaD

Programmer
Jan 26, 2001
25
CA
I have been looking for days on how to perform a - hopefully - simple task.

I have a MultiSelect Listbox on my Insert Page.

Code:
<asp:ListBox ID="ddlSite" 		 
		  DataSource="<%# dsSite.DefaultView %>" 
		  DataTextField="Site" 
		  DataValueField="Site"		 
		  Rows="5" 
		  runat="server" 
		  SelectionMode="multiple">
		  </asp:ListBox>

I want to have a MultiSelect Listbox on my Update (Edit) Page that shows which sites were selected on the Insert Page so the User does not need to reselect them, thus eliminating errors and wasting their time.

The 'ddlSite' field in my table (tblRequest) that recieved the inserted data stores the selected values separated by commas (ie: Birchmount,Longview,GlenEden).

How can I show in my Update Page listbox which items were selected on the Insert Page.

I'm working in C#.

TIA, Brenda
 
A simple loop will have to do in this case.

Split the comma separated list into an array:

string[] selectedItems = value.Split(',');

Then just iterate over that array, setting the items in the ddl to selected = true:

for(...)
{
ddl.Items.FindByText/Value(selectedItems).Selected = true;
}//for

Something along those lines. I'm not sure how you have your ddl setup w/ text/value, hence my Text/Value up there. Whichever method is appropriate is the one you should use.

-p

penny.gif
penny.gif

The answer to getting answered -- faq855-2992
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top