本文介绍了我得到这个错误 - “索引超出范围。必须是非负数且小于集合的大小。参数名称:index" .... plz help的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
foreach (GridViewRow row in grdCat.Rows)
{
CheckBox ch =(CheckBox)row.FindControl( CheckBox1);
if (ch.Checked)
{
int id = Convert.ToInt32(grdCat.DataKeys [row.RowIndex]。价值);
string qry = 从简报中选择电子邮件其中id =' + id + ';
SqlConnection con = new SqlConnection(ConString);
SqlCommand cmd = new SqlCommand(qry,con);
con.Open();
string EID = cmd.ExecuteScalar()。ToString();
con.Close();
EmailTo + = EID + ,;
}
}
解决方案
foreach (GridViewRow row in grdCat.Rows) { CheckBox ch = (CheckBox)row.FindControl("CheckBox1"); if (ch.Checked) { int id =Convert.ToInt32(grdCat.DataKeys[row.RowIndex].Value); string qry = "Select email from newsletter where id='" + id + "'"; SqlConnection con = new SqlConnection(ConString); SqlCommand cmd = new SqlCommand(qry, con); con.Open(); string EID = cmd.ExecuteScalar().ToString(); con.Close(); EmailTo += EID + ","; } }
解决方案
这篇关于我得到这个错误 - “索引超出范围。必须是非负数且小于集合的大小。参数名称:index" .... plz help的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!