Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 13th, 2004, 09:05 AM
Authorized User
 
Join Date: Jun 2003
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default setting mult. selections in listbox at page_load

Hi,

I have a confirmation page for entered records where a user can edit incorrect entries. One of those controls is a listbox, and on the original record entry the user can make multiple selections in this listbox.

My question is, on my edit page, how can I set the multiple selections chosen on the original record save as selected? I know how to populate the listbox with all available selections, and I would get the selections the user made from a stored procedure into my page (SELECT listItemVal FROM table WHERE registrationID = @registrationID). I just don't know how to loop through the listbox populated with all values and set the items whose values are equal to the selected items from my stored procedure = true.

Can someone please offer some advice?

Thanks,

John
 
Old April 14th, 2004, 07:39 AM
Registered User
 
Join Date: Apr 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Jtyson,

Use the below code snippet to solve your problem. Here ObjDr is a SqlDataReader and lstCourse is the name of my ListBox.

while (ObjDr.Read())
{
  foreach(ListItem LI in lstCourse.Items)
   {
    if(LI.Value.ToString() == ObjDr["YourFieldName"].ToString())
      {
    LI.Selected = true;
      }
   }
}

Hope this suffices your need!!

Best Regards
Vadivel

MVP ASP/ASP.NET
http://vadivel.blogspot.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
programmatically setting selections on a multiSELE rupen Javascript How-To 6 November 20th, 2006 10:14 AM
how do i get a handle on a listbox in page_load lcsgeek ASP.NET 2.0 Basics 3 June 19th, 2006 09:20 AM
C# ListBox Working With Multiple Selections pro-logic C# 1 October 9th, 2005 02:15 AM
multiple listbox selections written to a text fiel pascoag Access 0 October 14th, 2004 10:01 PM
Distinct fields from mult columns abbylee26 Classic ASP Basics 4 March 18th, 2004 12:47 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.