Solved

Create listbox at runtime c#

Posted on 2014-11-15
4
489 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 33

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 33

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

777 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