Re: Filling a dropdownlistbox with two items part 2
From: Nicholas Paldino [.NET/C# MVP] (mvp_at_spam.guard.caspershouse.com)
Date: 03/25/04
- Next message: Andreas Håkansson: "Re: Filling a drop down list box with two items"
- Previous message: Jeff B.: "Re: ANSI or Unicode"
- In reply to: Dave Bailey: "Filling a dropdownlistbox with two items part 2"
- Next in thread: Dave Bailey: "Re: Filling a dropdownlistbox with two items part 2"
- Reply: Dave Bailey: "Re: Filling a dropdownlistbox with two items part 2"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 25 Mar 2004 10:48:28 -0500
Dave,
Two things. First, make one call to CreateSystemCodeListDataSource. No
need to run twice and waste those cycles.
Second, your loop is using i <= count. Change to i < count. The index
count does not exist, since the collection starts at 0.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
"Dave Bailey" <anonymous@discussions.microsoft.com> wrote in message
news:93D95864-333D-4F03-9928-09FCEC05AB7A@microsoft.com...
> I have altered to code to read as follows:
>
> public void BindSystemCodeList()
> {
> int i = 0;
> sysCodeList.DataSource = CreateSystemCodeListDataSource();
> int count = CreateSystemCodeListDataSource().Count;
>
> for (i = 0; i <= count; i++)
> {
> sysCodeList.Items[i].Text = "text here";
> sysCodeList.Items[i].Value = "Value" + " - " + "Valdesc";
> }
> for (i = 0; i <= count; i++)
> {
> string[] str = sysCodeList.Items[i].Value.ToString().Split('-');
> }
>
> Now when I run the program I get the following error:
>
> Server Error in '/FiveYearPlan' Application.
> --------------------------------------------------------------------------
------
>
> Index was out of range. Must be non-negative and less than the size of the
collection. Parameter name: index
> Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
>
> Exception Details: System.ArgumentOutOfRangeException: Index was out of
range. Must be non-negative and less than the size of the collection.
Parameter name: index
>
> Source Error:
>
> An unhandled exception was generated during the execution of the current
web request. Information regarding the origin and location of the exception
can be identified using the exception stack trace below.
>
> Stack Trace:
>
>
> [ArgumentOutOfRangeException: Index was out of range. Must be
non-negative and less than the size of the collection.
> Parameter name: index]
> System.Collections.ArrayList.get_Item(Int32 index) +91
> System.Web.UI.WebControls.ListItemCollection.get_Item(Int32 index) +10
> FiveYearPlan.defaultForm.BindSystemCodeList() +73
> FiveYearPlan.defaultForm.Page_Load(Object sender, EventArgs e) +160
> System.Web.UI.Control.OnLoad(EventArgs e) +67
> System.Web.UI.Control.LoadRecursive() +35
> System.Web.UI.Page.ProcessRequestMain() +731
>
>
>
>
> --------------------------------------------------------------------------
------
> Version Information: Microsoft .NET Framework Version:1.1.4322.573;
ASP.NET Version:1.1.4322.573
>
> Can anyone help me with this error?
>
> Thanks,
>
> Dave
>
>
- Next message: Andreas Håkansson: "Re: Filling a drop down list box with two items"
- Previous message: Jeff B.: "Re: ANSI or Unicode"
- In reply to: Dave Bailey: "Filling a dropdownlistbox with two items part 2"
- Next in thread: Dave Bailey: "Re: Filling a dropdownlistbox with two items part 2"
- Reply: Dave Bailey: "Re: Filling a dropdownlistbox with two items part 2"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
Loading