开发者

DataGridCommandEventArgs Item.ItemIndex = -1?

开发者 https://www.devze.com 2023-03-01 20:48 出处:网络
Hello I have a DataGrid, which is defined like this: <asp:DataGrid ID=\"DG_XYZ\" runat=\"server\" DataKeyField=\"id\" OnItemCommand=\"DG_XYZ_ItemCommand\"> ....

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

精彩评论

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

关注公众号