Asp.Net GridviewRows are Null

jackwebb22002
jackwebb22002 used Ask the Experts™
on
This is strange to me.  I'm trying to perform an update on all the rows in my GridView.  After User verifcation, I try to go through the rows of the Gridview and update each.  However, the rows are being presented to me as null.

The null exception occurs in line 13.

Any thoughts?
protected void btnVerify_Click(object sender, EventArgs e)
    {
        String wrk;
        wrk = cbArchived.Checked == true ? "UnArchived" : "Archived";
        int numRows = gvJobs.Rows.Count;
        gvJobs.DataBind();
        archiveCount = 0;
        foreach (GridViewRow gvrIn in gvJobs.Rows)
        {
            if (gvrIn.RowType == DataControlRowType.DataRow)
            {
                archiveOrNotJob = (QJob)gvrIn.DataItem;
                archiveOrNotJob.Archived = !cbArchived.Checked;
                archiveCount++;
                Db.UpdateQJob(archiveOrNotJob);
            }
        }
        lblArchiveResult.Text = String.Format("Succussfully {0} {1:N0} Jobs", wrk, archiveCount);
        lblArchiveResult.Visible = true;
    }

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
You have written the line:

gvJobs.DataBind();

it will bind the grid view controll. But I think you have not specified the data source.

Author

Commented:
You got me to go back to the source of the data, which works
    protected void btnVerify_Click(object sender, EventArgs e)
    {
        String wrk;
        wrk = cbArchived.Checked == true ? "UnArchived" : "Archived";
        int numRows = gvJobs.Rows.Count;
        archiveCount = 0;
        foreach (QJob gvrIn in filteredJobs)
        {
            gvrIn.Archived = !cbArchived.Checked;
            archiveCount++;
            Db.UpdateQJob(gvrIn);
        }
        lblArchiveResult.Text = String.Format("Succussfully {0} {1:n0} Jobs", wrk, archiveCount);
        lblArchiveResult.Visible = true;
    }

Open in new window

Author

Commented:
You got me to think of going back to the source of the Gridview's rows, which i included in my response,  which actually works.

Thanks for making me think about it from another angle.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial