Check the below link, author has explained very nicely:

http://www.devmanuals.com/tutorials/ms/aspdotnet/databindgridviewprogrammatically.html