简体   繁体   中英

How to find a Gridview Footer label when there isn't always a footer

I have a gridview that I would like to extract the data in a footer from.

I have an issue as the footer doesn't always exist (for example if the gridview is empty).

How do I test for null against the label when the footer itself doesn't exist?

A simple if !null doesn't work as I get an "Object reference not set to an instance of an object." error.

if (GridView1.FooterRow.FindControl("TotalLbl") != null) //do stuff

Any pointers?

You need to check if GridView1.FooterRow is not null first. So it'd look like this: if(GridView1.FooterRow != null && GridView1.FooterRow.FindControl("TotalLbl") != null)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM