Solved

Create listbox at runtime c#

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

Accepted Solution

by:
it_saige earned 500 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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!
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

821 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