动态的给label赋值 急急急!
做的毕设想动态的给label赋值共有20个label 分别为Lab1,Lab2, ......Lab20
各位大虾帮忙看看下面代码是肿么了 急急急!
for (int i = 1; i < 21;i++ ) {
string classTime = ((Label)FindControl("Lab " + i.ToString())).Text.ToString();
string courseId = Request.QueryString["courseId"].ToString();
CourseTaInfo theInfo = new CourseTaInfo();
ArrayList infoList = CourseService.GetCourseTaOneInfo(courseId, classTime);
if (infoList.Count != 0)
{
theInfo = (CourseTaInfo)infoList[0];
((Label)FindControl("Lab " + i.ToString())).Text = theInfo.courseName.Trim() + "\n" + "(" + theInfo.teachName.Trim() + ")" + "\n" + "(" + theInfo.classId.Trim() + ")" + "\n" + "(" + theInfo.venue.Trim() + ")";
}
else
{
((Label)FindControl("Lab " + i.ToString())).Text = "";
}
}
错误:未将对象引用设置到对象的实例。