当前位置:编程学习 > C#/ASP.NET >>

索引(从零开始)必须大于或等于零,且小于参数列表的大小

GridView中有多列,Customer和Name是两个参数
window.open('Uploads.aspx?Customer={0}&Name={1}')


异常详细信息: System.FormatException: 索引(从零开始)必须大于或等于零,且小于参数列表的大小。

如果只用1个参数Customer={0}没有问题的. --------------------编程问答-------------------- 你的参数肯定有问题
把代码全帖出来 --------------------编程问答-------------------- row.Attributes["ondblclick"] = String.Format("javascript:dbl_click=true;window.open('Uploads.aspx?Customer={0} & Name={1}');", GridView1.DataKeys[row.RowIndex].Value.ToString());
--------------------编程问答--------------------
引用 2 楼 wmdf97 的回复:
row.Attributes["ondblclick"] = String.Format("javascript:dbl_click=true;window.open('Uploads.aspx?Customer={0} & Name={1}');", GridView1.DataKeys[row.RowIndex].Value.ToString());

这不只提供了GridView1.DataKeys[row.RowIndex].Value.ToString()一个参数吗?那Name的参数的值呢? --------------------编程问答-------------------- {0}需要一个参数,{1}需要另一个参数。
而你只给了一个参数。 --------------------编程问答--------------------
引用 3 楼 ojlovecd 的回复:
引用 2 楼 wmdf97 的回复:
row.Attributes["ondblclick"] = String.Format("javascript:dbl_click=true;window.open('Uploads.aspx?Customer={0} & Name={1}');", GridView1.DataKeys[row.RowIndex].Value.ToString()); 

 
这不只提供了GridView1.DataKeys[row.RowIndex].Value.ToString()一个参数吗?那Name的参数的值呢?

你只提供一个参数啊!!
还有个参数呢!! --------------------编程问答--------------------


            if (row.RowType == DataControlRowType.DataRow)
            {
                
                row.Attributes["ondblclick"] = String.Format("javascript:dbl_click=true;window.open('Uploads.aspx?Customer={0} & Name={1}');", GridView1.DataKeys[row.RowIndex].Value.ToString(),GridView1.DataKeys[row.RowIndex].Value.ToString());
                
            }



有2个参数就没有问题了,但是GridView1.DataKeys[row.RowIndex].Value.ToString()什么意思?能否把这两个指向到GridView的第3列和GridView的第5列 --------------------编程问答-------------------- GridView1.Rows[e.Row.Index].Cells[列].Value.ToString(); --------------------编程问答-------------------- 还是不行,GridView1.DataKeys[row.RowIndex].Value.ToString()语句是要放在protected override void Render(HtmlTextWriter writer)下面的
     --------------------编程问答--------------------


    protected override void Render(HtmlTextWriter writer)
    {
       

        foreach (GridViewRow row in GridView1.Rows)
        {
            if (row.RowType == DataControlRowType.DataRow)
            {
                
                row.Attributes["ondblclick"] = String.Format("javascript:dbl_click=true;window.open('Uploads.aspx?Customer={0} & Name={1}');", GridView1.DataKeys[row.RowIndex].Value.ToString(), GridView1.DataKeys[row.RowIndex].Value.ToString());

            }
        }

        base.Render(writer);
    }






GridView1.DataKeys[row.RowIndex].Value.ToString(), GridView1.DataKeys[row.RowIndex].Value.ToString());怎样才能指向到GridView的第3列和GridView的第5列 --------------------编程问答-------------------- 高手帮忙啊 --------------------编程问答-------------------- row.Cells[2].Value.ToString()//第三列
row.Cells[4].Value.ToString()//第五列 --------------------编程问答-------------------- 又遇到个问题,比如row.Cells[2].Value.ToString()列的值为空的时候,怎样让它取row.Cells[3].Value.ToString()列的值,如果第2和3列都为空就取固定值"none",请指教.




    protected override void Render(HtmlTextWriter writer)
    {
       

        foreach (GridViewRow row in GridView1.Rows)
        {
            if (row.RowType == DataControlRowType.DataRow)
            {
                
                row.Attributes["ondblclick"] = String.Format("javascript:dbl_click=true;window.open('Uploads.aspx?Customer={0} & Name={1}');", row.Cells[2].Value.ToString(),row.Cells[4].Value.ToString());

            }
        }

        base.Render(writer);
    }






--------------------编程问答-------------------- 代码重新发



    protected override void Render(HtmlTextWriter writer)
    {
       

        foreach (GridViewRow row in GridView1.Rows)
        {
            if (row.RowType == DataControlRowType.DataRow)
            {
                
                row.Attributes["ondblclick"] = String.Format("javascript:dbl_click=true;window.open('Uploads.aspx?Customer={0} & Name={1}');", row.Cells[2].Value.ToString(),row.Cells[4].Value.ToString());

            }
        }

        base.Render(writer);
    }






补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,