Solved

Create listbox at runtime c#

Posted on 2014-11-15
4
446 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 32

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 33

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 32

Accepted Solution

by:
it_saige earned 500 total points
ID: 40445055
0
 
LVL 33

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now