?
Solved

Create listbox at runtime c#

Posted on 2014-11-15
4
Medium Priority
?
615 Views
Last Modified: 2014-11-15
In the event LoadListBoxes(...);, I need code to create a few list boxes. The name of the listboxes are store in listBoxes object

Question: How can I complete the signature for this event and code it to create only those with Key = True?

   protected void Page_Load(object sender, EventArgs e)
    {
        Dictionary<string, bool> listBoxes =   new Dictionary<string, bool>();
        listBoxes.Add("First_Name",true);
        listBoxes.Add("LastName", false);
        listBoxes.Add("City", true);
        if (!IsPostBack==false)
        {
        }
        else
        {
            LoadListBoxes(Dictionary<string, bool> listBoxes);
        }
    }
    private void LoadListBoxes(Dictionary<string, bool> listBoxes)
{
}
    {

Open in new window

0
Comment
Question by:Mike Eghtebas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 34

Expert Comment

by:it_saige
ID: 40445041
Something like:
private void LoadListBoxes(Dictionary<string, bool> listBoxes)
{
	foreach (string box in (from listBox in listBoxes where listBox.Value select listBox.Key))
	{
		ListBox lb = new ListBox() { Name = box };
		// Do anything you want with the properties
		// Add the new listbox to your form or where ever.
	}
}

Open in new window


-saige-
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 40445050
Could you please replace the following line

// Add the new listbox to your form or where ever.

to add these controls anywhere on the webform?

And also, possibly give me a link where I can learn a little about positioning my controls on the webform?

Thanks,

Mike
0
 
LVL 34

Accepted Solution

by:
it_saige earned 2000 total points
ID: 40445055
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 40445112
This is great. I was able to use the dynamic positioning successfully.

Could you please also take a look at another question nobody touching it:

http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_28562832.html

Mike
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question