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

S

Stefan

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();


}
 
S

Stefan

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 said:
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 said:
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();


}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top