Gloria
Gloria

Reputation: 1325

How to check if FormView is empty from code behind

How can I check if a Form View is empty from code behind? I've tried DataItemCount ==0 but it doesn't seem to work. Thanks

if (FormView_imgBG.DataItemCount == 0)

            { //do stuff
            }
            else 

            {                 
            // do other stuff
            }

Upvotes: 2

Views: 2006

Answers (1)

romanoza
romanoza

Reputation: 4862

People are saying that the best place to check the DataItemCount property is in the FormView.DataBound event.

    protected void FormView1_DataBound(object sender, EventArgs e) {
        if (FormView1.DataItemCount == 0) {
        }
        else {
        }
    }

Upvotes: 2

Related Questions