Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Create listbox at runtime c#

Posted on 2014-11-15
4
Medium Priority
?
667 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
  • 2
  • 2
4 Comments
 
LVL 35

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 35

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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

885 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