-1

Hello I have a DataGrid, which is defined like this:

<asp:DataGrid ID="DG_XYZ" runat="server" DataKeyField="id" OnItemCommand="DG_XYZ_ItemCommand"> ....

Now, I in the DG_XYZ_ItemCommand method, I am trying to do this:

int id = Convert.ToInt32(DG_XYZ.DataKeys[e.Item.ItemIndex].ToString();

This gives an error when paging for example, because e.Item.ItemIndex is -1. Question is why? The method look like this:

protected void DG_XYZ_ItemCommand(object sender, DataGridCommandEventArgs e)
{
    int id = Convert.ToInt32(DG_XYZ.DataKeys[e.Item.ItemIndex].ToString();
    ...
}

Whats wrong here? Thanks :).

Govind Malviya
  • 13,627
  • 17
  • 68
  • 94
grady
  • 12,281
  • 28
  • 71
  • 110

1 Answers1

0

you paste your complete grid view code

bcz e.Item.ItemIndex start from 0

Sai Sherlekar
  • 1,804
  • 1
  • 17
  • 18