出错的地方应该不是你标注的这一行,你是单步调试的?检查第一行的转换对不对
int rowIndex = ((e.CommandSource as ImageButton).NamingContainer as GridViewRow).RowIndex;
int rowIndex = ((e.CommandSource as ImageButton).NamingContainer as GridViewRow).RowIndex;
说说看看,这一行怎么了?