try adding your assignment inside the following if statement
if(theGridViewRow.RowType == DataControlRowType.DataRow)
lblheader.Text = theGridViewRow.Cells(index).Text
probably you are getting error because you are looking into header row and footer row
thanks,
Hemant