开发者

DataGridCommandEventArgs Item.ItemIndex = -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].T开发者_如何学GooString();
    ...
}

Whats wrong here? Thanks :).


you paste your complete grid view code

bcz e.Item.ItemIndex start from 0

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜