Replace all queries to #grid with a variable.