我试图保存一个遍历10列的列表,并且我的代码抛出System.IndexOutOfRangeException。我经历了所有其他解决方案,他们没有解决我的问题。内部异常具有NULL。
for (int i = 1; i <= 9; i++)
{
txtIndicator = (TextBox)this.UpdatePanel1.FindControl("txtIndicator" + i);
if (manipType.Equals("add"))
{
try
{
Databases.WeeklySurveillance iws = new Databases.WeeklySurveillance()
{
WeekEnding = DateTime.Parse(tmpMondayDate),
FacilityCode = Session["facility"].ToString().Split(":".ToCharArray())[0],
AgeGroup = iwsDataItems[i - 1].AgeGroup,
Condition = iwsDataItems[i - 1].Condition,
Position = i,
Batch = 2019,
Total = int.Parse(txtIndicator.Text),
Description = Session["facility"].ToString().Split(":".ToCharArray())[1].Trim(),
DateStamp = DateTime.Now
};
healthDC.WeeklySurveillances.Add(iws);
}
}
}