-1

您好,我有一个 DataGrid,它的定义如下:

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

现在,我在 DG_XYZ_ItemCommand 方法中,我正在尝试这样做:

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

例如,这在分页时会出错,因为 e.Item.ItemIndex 为 -1。问题是为什么?该方法如下所示:

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

这里有什么问题?谢谢 :)。

4

1 回答 1

0

您粘贴完整的网格视图代码

bcz e.Item.ItemIndex 从 0 开始

于 2011-05-04T07:26:13.017 回答