1

我的 gridview Row 命令代码看起来像

protected void GridView_Admins_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        GridView sourceGrid = sender as GridView;

        int currentIndex = 0;
        GridViewRow currentRow = null;

        if (string.Compare(e.CommandName, "SHOW", true) == 0)
        {
            if (int.TryParse(e.CommandArgument.ToString(), out currentIndex))
            {

                currentRow = sourceGrid.Rows[currentIndex];

                if (long.TryParse(sourceGrid.DataKeys[currentRow.RowIndex].Values["EmployeeID"].ToString(), out this.employeeId))
                    this.ShowAdministrativeRightsForUser();
            }
        }
    }

我还在gridview中启用了分页。当我想编辑记录时,我单击特定单元格,我可以编辑记录。但是,当我在第二页上单击单元格以编辑记录时,我在行显示currentRow = sourceGrid.Rows[currentIndex];索引超出范围时出现错误。有什么问题?

4

1 回答 1

0

使用它来获取索引:

int index = Convert.ToInt32(e.CommandArgument);
于 2012-04-25T07:22:27.060 回答