Professional Web Applications Themes

Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index - ASP.NET

Hey Folks,(New to .NET) This is driving me NUTZ... If anyone out there can resolve this from me I would greatly appreciate it... Line 238: Line 239: // Gets the value of the key field of the row being updated Line 240: string key = DataGrid1.DataKeys[e.Item.ItemIndex].ToString(); Line 241: private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { string queueOwner; // Gets the value of the key field of the row being updated string key = DataGrid1.DataKeys[e.Item.ItemIndex].ToString(); // The first column -- Cells(0) -- contains the Update and Cancel buttons. TextBox tb; // Gets the value the TextBox control in the third column ...

  1. #1

    Default Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

    Hey Folks,(New to .NET)
    This is driving me NUTZ... If anyone out there can resolve this from me
    I would greatly appreciate it...

    Line 238:
    Line 239: // Gets the value of the key field of the row being updated
    Line 240: string key = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
    Line 241:



    private void DataGrid1_UpdateCommand(object source,
    System.Web.UI.WebControls.DataGridCommandEventArgs e)

    {


    string queueOwner;


    // Gets the value of the key field of the row being updated

    string key = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();



    // The first column -- Cells(0) -- contains the Update and Cancel buttons.

    TextBox tb;

    // Gets the value the TextBox control in the third column

    tb = (TextBox)(e.Item.Cells[3].Controls[0]);

    queueOwner = tb.Text;

    dsNewsGroupID.DevComm_NG_ListRow r;

    r = dsNewsGroupID.DevComm_NG_List.FindByNewsgroupID(in t.P(key));

    // Updates the dataset table.

    r.QueueOwner = queueOwner;


    // Calls a SQL statement to update the database from the dataset

    sqlDataAdapter1.Update(dataSet1);

    // Takes the DataGrid row out of editing mode

    DataGrid1.EditItemIndex = -1;

    // Refreshes the grid

    DataGrid1.DataBind();


    }


    Stefan Guest

  2. #2

    Default Re: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

    first of all, you don't need to post this all over the internet, one well
    chosen newsgroup will do nicely.
    here is an article describing your problem
    [url]http://support.microsoft.com/default.aspx?scid=kb;en-us;555074[/url]

    --
    Regards,
    Alvin Bruney
    [ASP.NET MVP [url]http://mvp.support.microsoft.com/default.aspx][/url]
    Got tidbits? Get it here... [url]http://tinyurl.com/27cok[/url]
    "Stefan" <StefanCrazykode.problem> wrote in message
    news:OJmCRmpdEHA.228TK2MSFTNGP11.phx.gbl...
    > Hey Folks,(New to .NET)
    > This is driving me NUTZ... If anyone out there can resolve this from me
    > I would greatly appreciate it...
    >
    > Line 238:
    > Line 239: // Gets the value of the key field of the row being updated
    > Line 240: string key = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
    > Line 241:
    >
    >
    >
    > private void DataGrid1_UpdateCommand(object source,
    > System.Web.UI.WebControls.DataGridCommandEventArgs e)
    >
    > {
    >
    >
    > string queueOwner;
    >
    >
    > // Gets the value of the key field of the row being updated
    >
    > string key = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
    >
    >
    >
    > // The first column -- Cells(0) -- contains the Update and Cancel buttons.
    >
    > TextBox tb;
    >
    > // Gets the value the TextBox control in the third column
    >
    > tb = (TextBox)(e.Item.Cells[3].Controls[0]);
    >
    > queueOwner = tb.Text;
    >
    > dsNewsGroupID.DevComm_NG_ListRow r;
    >
    > r = dsNewsGroupID.DevComm_NG_List.FindByNewsgroupID(in t.P(key));
    >
    > // Updates the dataset table.
    >
    > r.QueueOwner = queueOwner;
    >
    >
    > // Calls a SQL statement to update the database from the dataset
    >
    > sqlDataAdapter1.Update(dataSet1);
    >
    > // Takes the DataGrid row out of editing mode
    >
    > DataGrid1.EditItemIndex = -1;
    >
    > // Refreshes the grid
    >
    > DataGrid1.DataBind();
    >
    >
    > }
    >
    >

    Alvin Bruney [MVP] Guest

  3. #3

    Default Re: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

    Hey folks,
    Wow... After only 4 hours... I figured out the Index out of range error
    and now have run into the error below ... Any help would be greatly
    appreciated ...


    Exception Details: System.NullReferenceException: Object reference not set
    to an instance of an object.

    Line 256: Session["mydataset"] = dataSet1;
    Line 257: // Updates the dataset table.
    Line 258: r.QueueOwner= queueOwner;
    Line 259:
    Line 260: // Calls a SQL statement to update the database from the
    dataset
    Source File: c:\inetpub\wwwroot\qoupdate\qoupdate.aspx.cs Line: 258

    Stack Trace:

    [NullReferenceException: Object reference not set to an instance of an
    object.]
    QoUpdate.WebForm1.DataGrid1_UpdateCommand(Object source,
    DataGridCommandEventArgs e) in
    c:\inetpub\wwwroot\qoupdate\qoupdate.aspx.cs:258

    System.Web.UI.WebControls.DataGrid.OnUpdateCommand (DataGridCommandEventArgs
    e)
    System.Web.UI.WebControls.DataGrid.OnBubbleEvent(O bject source, EventArgs
    e)
    System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
    System.Web.UI.WebControls.DataGridItem.OnBubbleEve nt(Object source,
    EventArgs e)
    System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
    System.Web.UI.WebControls.Button.OnCommand(Command EventArgs e)

    System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePo
    stBackEvent(String eventArgument)
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
    sourceControl, String eventArgument)
    System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
    System.Web.UI.Page.ProcessRequestMain()




    KODE -
    ----------------------------------------------------------------------------
    -----------------------------

    r = dsNewsGroupID.DevComm_NG_List.FindByNewsgroupID(in t.P(key));
    // Updates the dataset table.

    r.QueueOwner= queueOwner;





    "Stefan" <StefanCrazykode.problem> wrote in message news:...
    > Hey Folks,(New to .NET)
    > This is driving me NUTZ... If anyone out there can resolve this from
    me
    > I would greatly appreciate it...
    >
    > Line 238:
    > Line 239: // Gets the value of the key field of the row being updated
    > Line 240: string key = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
    > Line 241:
    >
    >
    >
    > private void DataGrid1_UpdateCommand(object source,
    > System.Web.UI.WebControls.DataGridCommandEventArgs e)
    >
    > {
    >
    >
    > string queueOwner;
    >
    >
    > // Gets the value of the key field of the row being updated
    >
    > string key = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
    >
    >
    >
    > // The first column -- Cells(0) -- contains the Update and Cancel buttons.
    >
    > TextBox tb;
    >
    > // Gets the value the TextBox control in the third column
    >
    > tb = (TextBox)(e.Item.Cells[3].Controls[0]);
    >
    > queueOwner = tb.Text;
    >
    > dsNewsGroupID.DevComm_NG_ListRow r;
    >
    > r = dsNewsGroupID.DevComm_NG_List.FindByNewsgroupID(in t.P(key));
    >
    > // Updates the dataset table.
    >
    > r.QueueOwner = queueOwner;
    >
    >
    > // Calls a SQL statement to update the database from the dataset
    >
    > sqlDataAdapter1.Update(dataSet1);
    >
    > // Takes the DataGrid row out of editing mode
    >
    > DataGrid1.EditItemIndex = -1;
    >
    > // Refreshes the grid
    >
    > DataGrid1.DataBind();
    >
    >
    > }
    >
    >

    Stefan Guest

  4. #4

    Default Re: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

    Hey Alvin,
    Thanks for the followup ... It turns out the DataKeyField was showing
    empty... So I added the DataKeyField with primary key ..

    AutoGenerateColumns="False" DataSource="<%# dataSet1 %>"
    DataKeyField="NewsGroupID" Visible="False" Font-Names="Arial">

    If anyone has any assistance on my other error... All I have to do is get by
    that error and I am done... :0) hopefully ...

    Thanks
    Stefan

    "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
    news:u6iAnIrdEHA.212TK2MSFTNGP12.phx.gbl...
    > first of all, you don't need to post this all over the internet, one well
    > chosen newsgroup will do nicely.
    > here is an article describing your problem
    > [url]http://support.microsoft.com/default.aspx?scid=kb;en-us;555074[/url]
    >
    > --
    > Regards,
    > Alvin Bruney
    > [ASP.NET MVP [url]http://mvp.support.microsoft.com/default.aspx][/url]
    > Got tidbits? Get it here... [url]http://tinyurl.com/27cok[/url]
    > "Stefan" <StefanCrazykode.problem> wrote in message
    > news:OJmCRmpdEHA.228TK2MSFTNGP11.phx.gbl...
    > > Hey Folks,(New to .NET)
    > > This is driving me NUTZ... If anyone out there can resolve this from
    me
    > > I would greatly appreciate it...
    > >
    > > Line 238:
    > > Line 239: // Gets the value of the key field of the row being updated
    > > Line 240: string key = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
    > > Line 241:
    > >
    > >
    > >
    > > private void DataGrid1_UpdateCommand(object source,
    > > System.Web.UI.WebControls.DataGridCommandEventArgs e)
    > >
    > > {
    > >
    > >
    > > string queueOwner;
    > >
    > >
    > > // Gets the value of the key field of the row being updated
    > >
    > > string key = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
    > >
    > >
    > >
    > > // The first column -- Cells(0) -- contains the Update and Cancel
    buttons.
    > >
    > > TextBox tb;
    > >
    > > // Gets the value the TextBox control in the third column
    > >
    > > tb = (TextBox)(e.Item.Cells[3].Controls[0]);
    > >
    > > queueOwner = tb.Text;
    > >
    > > dsNewsGroupID.DevComm_NG_ListRow r;
    > >
    > > r = dsNewsGroupID.DevComm_NG_List.FindByNewsgroupID(in t.P(key));
    > >
    > > // Updates the dataset table.
    > >
    > > r.QueueOwner = queueOwner;
    > >
    > >
    > > // Calls a SQL statement to update the database from the dataset
    > >
    > > sqlDataAdapter1.Update(dataSet1);
    > >
    > > // Takes the DataGrid row out of editing mode
    > >
    > > DataGrid1.EditItemIndex = -1;
    > >
    > > // Refreshes the grid
    > >
    > > DataGrid1.DataBind();
    > >
    > >
    > > }
    > >
    > >
    >
    >

    Stefan Guest

  5. #5

    Default Re: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

    probably not the case here but i had this same problem using Session
    variables the same way you are. ie: initializing/creating them at the time
    you need them. the ref books i've read say this is OK but i had problems. to
    get rid of the error, i ended up having to initialize all my Session vars in
    the SessionStart handler then resetting the values when necessary in my main
    code.

    "Stefan" <StefanCrazykode.problem> wrote in message
    news:uNiCWFsdEHA.2696TK2MSFTNGP09.phx.gbl...
    > Hey folks,
    > Wow... After only 4 hours... I figured out the Index out of range
    error
    > and now have run into the error below ... Any help would be greatly
    > appreciated ...
    >
    >
    > Exception Details: System.NullReferenceException: Object reference not set
    > to an instance of an object.
    >
    > Line 256: Session["mydataset"] = dataSet1;
    > Line 257: // Updates the dataset table.
    > Line 258: r.QueueOwner= queueOwner;
    > Line 259:
    > Line 260: // Calls a SQL statement to update the database from the
    > dataset
    > Source File: c:\inetpub\wwwroot\qoupdate\qoupdate.aspx.cs Line: 258
    >
    > Stack Trace:
    >
    > [NullReferenceException: Object reference not set to an instance of an
    > object.]
    > QoUpdate.WebForm1.DataGrid1_UpdateCommand(Object source,
    > DataGridCommandEventArgs e) in
    > c:\inetpub\wwwroot\qoupdate\qoupdate.aspx.cs:258
    >
    >
    System.Web.UI.WebControls.DataGrid.OnUpdateCommand (DataGridCommandEventArgs
    > e)
    > System.Web.UI.WebControls.DataGrid.OnBubbleEvent(O bject source,
    EventArgs
    > e)
    > System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
    > System.Web.UI.WebControls.DataGridItem.OnBubbleEve nt(Object source,
    > EventArgs e)
    > System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
    > System.Web.UI.WebControls.Button.OnCommand(Command EventArgs e)
    >
    >
    System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePo
    > stBackEvent(String eventArgument)
    > System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
    > sourceControl, String eventArgument)
    > System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
    > System.Web.UI.Page.ProcessRequestMain()
    >
    >
    >
    >
    > KODE -
    > --------------------------------------------------------------------------
    --
    > -----------------------------
    >
    > r = dsNewsGroupID.DevComm_NG_List.FindByNewsgroupID(in t.P(key));
    > // Updates the dataset table.
    >
    > r.QueueOwner= queueOwner;
    >
    >
    >
    >
    >
    > "Stefan" <StefanCrazykode.problem> wrote in message news:...
    > > Hey Folks,(New to .NET)
    > > This is driving me NUTZ... If anyone out there can resolve this from
    > me
    > > I would greatly appreciate it...
    > >
    > > Line 238:
    > > Line 239: // Gets the value of the key field of the row being updated
    > > Line 240: string key = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
    > > Line 241:
    > >
    > >
    > >
    > > private void DataGrid1_UpdateCommand(object source,
    > > System.Web.UI.WebControls.DataGridCommandEventArgs e)
    > >
    > > {
    > >
    > >
    > > string queueOwner;
    > >
    > >
    > > // Gets the value of the key field of the row being updated
    > >
    > > string key = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
    > >
    > >
    > >
    > > // The first column -- Cells(0) -- contains the Update and Cancel
    buttons.
    > >
    > > TextBox tb;
    > >
    > > // Gets the value the TextBox control in the third column
    > >
    > > tb = (TextBox)(e.Item.Cells[3].Controls[0]);
    > >
    > > queueOwner = tb.Text;
    > >
    > > dsNewsGroupID.DevComm_NG_ListRow r;
    > >
    > > r = dsNewsGroupID.DevComm_NG_List.FindByNewsgroupID(in t.P(key));
    > >
    > > // Updates the dataset table.
    > >
    > > r.QueueOwner = queueOwner;
    > >
    > >
    > > // Calls a SQL statement to update the database from the dataset
    > >
    > > sqlDataAdapter1.Update(dataSet1);
    > >
    > > // Takes the DataGrid row out of editing mode
    > >
    > > DataGrid1.EditItemIndex = -1;
    > >
    > > // Refreshes the grid
    > >
    > > DataGrid1.DataBind();
    > >
    > >
    > > }
    > >
    > >
    >
    >

    SilentCry Guest

Similar Threads

  1. STRING INDEX OUT OF RANGE: -12
    By xcoldnet in forum Coldfusion Database Access
    Replies: 0
    Last Post: May 24th, 08:59 PM
  2. String index out of range: -6
    By colesc8 in forum Coldfusion Security
    Replies: 5
    Last Post: February 28th, 01:44 PM
  3. index value out-of-range error
    By Michael Coughlin in forum ASP.NET Data Grid Control
    Replies: 10
    Last Post: February 25th, 01:49 AM
  4. #21554 [Com]: Can't turn off TTF anti-aliasing with negative color index in 4.3.0
    By webmaster at lacoccinelle dot net in forum PHP Development
    Replies: 0
    Last Post: October 2nd, 05:00 PM
  5. Replies: 0
    Last Post: August 4th, 12:40 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139