This example uses a MySQL DB with a table named tree with the fields id, name, and parent_id. The parent_id will be NULL for root elements. The SQL is kept simple (no autoinc, no FK, etc).
This article will show you how to add links and class to each node in ctreeview. so you can attach events in js by obtaining handler on anchor or class.