Author Topic: ASP.NET/C# problem  (Read 575 times)

0 Members and 1 Guest are viewing this topic.

Offline El JoNNo

  • Posts: 1779
  • Gender: Male
  • EMOTRUCCI
ASP.NET/C# problem
« on: July 30, 2012, 12:44:19 PM »
So my problem is the bold line of code is giving me "Index was outside the bounds of the array." error. It's an issue with the italicized bit. Am I not able to make an array out of DropDownLists and then add to the list? Should I use something else like an arraylist or collection or something? Oh the 'ID' variable is set to 1 right now. Any help would be appreciated.

         
        DropDownList ddlHospital = new DropDownList();
        DropDownList[] dynamicDropDownList = new DropDownList[ID];       
       
        ddlHospital.ID = "dropDownList" + ID.ToString();
        ControlsPlaceHolder.Controls.Add(ddlHospital);
        dynamicDropDownList[ID] = ddlHospital;
       
        ddlHospital.Items.Add(new ListItem("Select a Hospital"));

Offline theseoafs

  • When the lights go down in the city, and the sun shines on the bayyyyy
  • Posts: 5573
  • Gender: Male
  • Hello! My name is Elder Price
Re: ASP.NET/C# problem
« Reply #1 on: July 30, 2012, 12:47:42 PM »
In the italicized line, you're referencing the second element of the array, when the array is only one element long.  That's probably your problem.  Should be

dynamicDropDownList[0] = ddlHospital;

Offline El JoNNo

  • Posts: 1779
  • Gender: Male
  • EMOTRUCCI
Re: ASP.NET/C# problem
« Reply #2 on: July 30, 2012, 12:55:05 PM »
That did the trick

I forgot that C# doesn't start at 1. This is my first programming job in about 6 years, I'm a bit rusty. lol


Thank you, for the help.  :tup
 

Offline theseoafs

  • When the lights go down in the city, and the sun shines on the bayyyyy
  • Posts: 5573
  • Gender: Male
  • Hello! My name is Elder Price
Re: ASP.NET/C# problem
« Reply #3 on: July 30, 2012, 12:58:11 PM »
Indexes for arrays almost always start at 0, actually.  They definitely do in all languages with C-style syntax, anyway.

Best of luck!

Offline rumborak

  • DT.net Veteran
  • ****
  • Posts: 26664
Re: ASP.NET/C# problem
« Reply #4 on: July 31, 2012, 10:39:25 PM »
I actually once worked with a C toolkit that used the memory address of the zeroeth element for storing the number of elements in that array (by casting it to an int regardless of what the array type actually was), and the first real array element started at the +1 element. It was a total clusterfuck to debug.

rumborak
"I liked when Myung looked like a women's figure skating champion."

Offline theseoafs

  • When the lights go down in the city, and the sun shines on the bayyyyy
  • Posts: 5573
  • Gender: Male
  • Hello! My name is Elder Price
Re: ASP.NET/C# problem
« Reply #5 on: July 31, 2012, 11:54:39 PM »
Oh, dude. :lol  That sounds horrific.

Offline El JoNNo

  • Posts: 1779
  • Gender: Male
  • EMOTRUCCI
Re: ASP.NET/C# problem
« Reply #6 on: August 01, 2012, 05:15:24 AM »
Why?..?.. Would someone do that? :lol

Offline rumborak

  • DT.net Veteran
  • ****
  • Posts: 26664
Re: ASP.NET/C# problem
« Reply #7 on: August 01, 2012, 09:58:27 PM »
Two words: Research Code.

There's a lot of CS PhD's who can't code their way out of a paper bag. They write horrendous code, and as long as it doesn't crash until their experiment is over, it's golden.

rumborak
"I liked when Myung looked like a women's figure skating champion."

Offline El JoNNo

  • Posts: 1779
  • Gender: Male
  • EMOTRUCCI
Re: ASP.NET/C# problem
« Reply #8 on: August 02, 2012, 05:35:57 AM »
Oh I see.. I feel your pain. The hospital I work at uses a patient care system that is comprised entirely of flat tables. Not a single relational database in the whole system. It's horrible and I hate everything about it.

Offline jag66

  • Posts: 757
Re: ASP.NET/C# problem
« Reply #9 on: August 02, 2012, 05:38:28 AM »
Oh I see.. I feel your pain. The hospital I work at uses a patient care system that is comprised entirely of flat tables. Not a single relational database in the whole system. It's horrible and I hate everything about it.

Indeed. Our company has just taken on a huge health service project - apparently their databases reek of that same problem.