本文介绍了错误-索引超出范围.必须为非负数并且小于集合的大小.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么此错误索引超出范围.必须为非负数并且小于集合的大小.在下面给出的行中

GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow;


参数名称:index

我的CS代码在下面给出

Why this error Index was out of range. Must be non-negative and less than the size of the collection. in the line given below

GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow;


Parameter name: index

my cs code is given below

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

推荐答案



这篇关于错误-索引超出范围.必须为非负数并且小于集合的大小.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 07:01