(Label)GridView1.FooterRow.FindControl("Label2");------->>未将对象引用设置到对象的实例?
下列代码,我执行gridview条件查询时,当查询出的数据为空后,再换个条件查询就报错,不知怎么回事:
Label lb = (Label)GridView1.FooterRow.FindControl("Label2");------->>未将对象引用设置到对象的实例。
代码:
int sum = 0;
decimal wwww = 0;
protected void Page_Load(object sender, EventArgs e)
{
DataView dv = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
foreach (DataRow ddd in dv.Table.Rows)
{
wwww += Convert.ToDecimal(dv.Table.Rows[sum][8]);
sum += 1;
}
Label lb = (Label)GridView1.FooterRow.FindControl("Label2");
lb.Text = wwww.ToString();
}