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


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
>
>


Relevant Pages

  • Re: Updated info
    ... An unhandled exception occurred 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. ... We've opened ports 443 and 4125 in the Netopia router but still can't get a RWW logon prompt. ...
    (microsoft.public.windows.server.sbs)
  • Re: trouble displaying image stored in database
    ... Using themed css files requires a header control on the page. ... Exception Details: System.InvalidOperationException: Using themed css files ... An unhandled exception was generated during the execution of the current web ... be identified using the exception stack trace below. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: hexadecimal value 0x01, is an invalid character
    ... An unhandled exception occurred during the execution of the ... > current web request. ... > exception can be identified using the exception stack trace below. ... > postDataKey, NameValueCollection values) ...
    (microsoft.public.dotnet.framework.aspnet)
  • Server Error in / Application.
    ... current web request. ... Please review the stack trace for more information about ... Exception Details: System.ArgumentOutOfRangeException: Specified argument ... An unhandled exception was generated during the execution of the current web ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: Bad Data. Any idea what this means?
    ... | the current web request. ... Please review the stack trace for more ... | Exception Details: System.Security.Cryptography.CryptographicException: ... | An unhandled exception was generated during the execution of the ...
    (microsoft.public.dotnet.security)

Loading