应用程序中'/WebSite8'服务器错误。指数超出范围。必须是非负数且小于集合的大小。参数名称:索引



描述:

执行当前Web请求期间发生了例外。请查看堆栈跟踪以获取有关错误及其在代码中起源的更多信息。

例外详细信息:

System.Argument Out Of Range Exception: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

代码:

  protected void ImageButton1_Click (object sender, EventArgs e)
    {
        ImageButton lnkbtn = sender as ImageButton;
        GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow;
        
        
           string filePath = GridView2.DataKeys[gvrow.RowIndex].Value.ToString();
            Response.ContentType = "image/jpg";
            Response.AddHeader("Content-Disposition", "attachment;filename="" + filePath + """);
            Response.TransmitFile(Server.MapPath(filePath));
            Response.End();
        
    }

看上去对我来说,您目前正在面对问题

string filePath = GridView2.DataKeys[gvrow.RowIndex].Value.ToString();

当您试图提取Datakey的值时,GVROW.RowIndex的值大于元素计数。

尝试调试并查看元素计数和gvrow.RowIndex正在设置什么。

相关内容

最新更新