For the fitness function of any GA you have to define an algorithm that returns the maximum (or minimum, depending on the kind of problem) value for optimal solutions.
For the knapsack problem, the fitness is typically defined as the total value of all items packed, and the optimal solution would be the one with the highest fitness. This should answer your question: simply write a function that calculates the sum of the value of all packed items.
That's the easy part.
It gets more tricky when you consider how you're going to create the next generation, since you have to watch out for the knapsack limitations. One way would be to specify special genetic operators that ensure that the offspring automatically fulfils the restriction. A second would be an additional step that weeds out all offspring that breach the restrictions, and then keep producing offspring until you have a sufficent number of new solutions.
You could also turn the hard limit(s) into a soft limit by allowing 'bad' solutions that exceed the capacity of the knapsack and instead adding a penalty to the fitness function result, e. g.
modified_fitness = max_fitness*A - excess_of_limits*B
where
max_fitness
is an estimate for the maximum achievable fitness value (using the unpenalized fitness function),
A
is a reducing factor small enough to reduce that estimate well below realistically achievable values (obviously depends on how well you can estimate - some value between 0.5 and 0.9 should work for most cases),
excess_of_limits
is the amount by which the evaluated solution exceeds the knapsack limits, and
B
is some scaling factor putting the excess into relation to the approximate size of the fitness value.
Finding good values for these constants will probably require some trial (and error). Or you could ask the user to enter these values at runtime, so you don't have to repeatedly change the program.