DataGrid1.DataKeys[e.Item.ItemIndex] array index out of bounds

J

Joel Finkel

Folks,

Can someone please explan why this this line of code works fine when executed within an ItemCommand (that is, once the data are fully bound), but throws an exception when it is executed withn an ItemBound (when the data are being bound to the grid)? The exception is an array out of bounds.

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

Thanks in advance.

Joel Finkel
(e-mail address removed)
 
J

Joel Finkel

Many thanks!

Hi

You need to check the ItemType before using the Statement. Try this :

if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
string strID = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
}



HTH
Prasad
Folks,

Can someone please explan why this this line of code works fine when executed within an ItemCommand (that is, once the data are fully bound), but throws an exception when it is executed withn an ItemBound (when the data are being bound to the grid)? The exception is an array out of bounds.

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

Thanks in advance.

Joel Finkel
(e-mail address removed)
 

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

Forum statistics

Threads
474,266
Messages
2,571,075
Members
48,772
Latest member
Backspace Studios

Latest Threads

Top