Index was out of range. Must be non-negative and less than the size of the collection. Parameter nam

Discussion in 'ASP .Net Datagrid Control' started by Stefan, Jul 31, 2004.

  1. Stefan

    Stefan Guest

    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(int.Parse(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, Jul 31, 2004
    #1
    1. Advertising

  2. 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
    http://support.microsoft.com/default.aspx?scid=kb;en-us;555074

    --
    Regards,
    Alvin Bruney
    [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
    Got tidbits? Get it here... http://tinyurl.com/27cok
    "Stefan" <> 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(int.Parse(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], Jul 31, 2004
    #2
    1. Advertising

  3. Stefan

    Stefan Guest

    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:...
    > 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
    > http://support.microsoft.com/default.aspx?scid=kb;en-us;555074
    >
    > --
    > Regards,
    > Alvin Bruney
    > [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
    > Got tidbits? Get it here... http://tinyurl.com/27cok
    > "Stefan" <> 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(int.Parse(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, Jul 31, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page