《指定参数超出有效值范围》我在ASP.NetGridView控件中使用TextBoxes添加动态行。但是当我点击我的添加新行按钮时,出现以下错误。指定的参数超出有效值范围。参数名称:index可能是什么错误?我的.aspx文件中的代码ButtonAdd_Click()的C#代码if(ViewState["CurrentTable"]!=null){数据行drCurrentRow=null;if(dtCurrentTable.Rows.Count>0){for(inti=1;i<=dtCurrentTable.Rows.Count;i++){//提取文本框值TextBoxbox1=(TextBox)Gridview1.Rows[rowIndex].Cells[1].FindControl("txt_type");TextBoxbox2=(TextBox)Gridview1.Rows[rowIndex].Cells[2].FindControl("txt_total");TextBoxbox3=(TextBox)Gridview1.Rows[rowIndex].Cells[3].FindControl("txt_max");TextBoxbox4=(TextBox)Gridview1.Rows[rowIndex].Cells[4].FindControl("txt_min");TextBoxbox5=(TextBox)Gridview1.Rows[rowIndex].Cells[5].FindControl("txt_rate");drCurrentRow=dtCurrentTable.NewRow();dtCurrentTable.Rows[i-1]["Column1"]=box1.Text;dt电流Table.Rows[i-1]["Column2"]=box2.Text;dtCurrentTable.Rows[i-1]["Column3"]=box3.Text;dtCurrentTable.Rows[i-1]["Column4"]=box4.Text;dtCurrentTable.Rows[i-1]["Column5"]=box5.Text;行索引++;}dtCurrentTable.Rows.Add(drCurrentRow);ViewState["CurrentTable"]=dtCurrentTable;.DataBind();}}else{Response.Write("ViewState为空");你似乎想从5个项目的集合中获取5个项目查看你的代码,你似乎是从1中的第二个值开始的集合中获取。集合是从零开始的,所以你应该从索引0处的项目开始。试试这个:TextBoxbox1=(TextBox)Gridview1.Rows[i].Cells[0].FindControl("txt_type");TextBoxbox2=(TextBox)Gridview1.Rows[i].Cells[1].FindControl("txt_total");TextBoxbox3=(TextBox)Gridview1.Rows[i].Cells[2].FindControl("txt_max");TextBoxbox4=(TextBox)Gridview1.Rows[i].Cells[3].FindControl("txt_min");TextBoxbox5=(TextBox)Gridview1.Rows[i].Cells[4].FindControl("txt_rate");尝试这个。如果(ViewState["CurrentTable"]!=null){DataTabledtCurrentTable=(DataTable)ViewState["CurrentTable"];数据行drCurrentRow=null;if(dtCurrentTable.Rows.Count>0){for(inti=1;i我遇到了同样的问题,因为我试图在非基础索引中使用0值,即从1开始,而不是从0开始.以上就是C#学习教程:《指定参数超出有效值范围》分享的全部内容,如果对你有用,需要了解更多C#学习教程,希望大家多多关注——-本文收集自网络,不代表立场,如涉及侵权,请点右联系管理员删除,转载请注明出处:
