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].T开发者_如何学GooString();
...
}
Whats wrong here? Thanks :).
you paste your complete grid view code
bcz e.Item.ItemIndex start from 0
精彩评论