The nervous system grants animals the ability to react to the complex and ever-changing environment. The ability of the nervous system to control behavior relies not only on the functional properties of individual neurons, but also on the specific pattern of connections in the neural circuits that make up the brain. This dissertation presents the functional study of a simple circuit, specifically the egg-laying circuit in the nematode Caenorhabditis elegan, as a model to understand the principles by which networks of neurons generate behavioral patterns. We first studied the circuit mechanism for individual egg-laying events using neural imaging and laser microsurgery. Our results indicated that the HSN and VC motorneurons together with vulval muscles (vm1 and vm2) comprise a core circuit that produces egg- laying events upon activation in the absence of sensory inputs. HSN serves as the command neuron of this core circuit, while the VCs, which are reciprocally connected to HSNs, provide a negative feedback loop as well as redundantly exciting the vulval muscles. The roles of two neurotransmitters expressed in these motorneurons, acetycholine and serotonin, have been investigated by directly monitoring both the activities of neurons in the egg-laying circuit in biosynthetic mutants. With this information about the functional roles of the egg-laying neurons, the egg-laying circuit provides a nice system for studying the effects of specific receptors and channels on neuronal function. As an example, we characterized a newly cloned novel voltage gated cation channel, NCA-1, and demonstrated its function in cellbody-to-synapse excitation in the HSNs. Based on our results, we have proposed a theoretical model for how the clustered temporal pattern in the egg-laying behavior is generated in wild type animals. The VCs are suggested to work as "the single egg counter" that is activated by individual egg-laying events and inhibits the command neuron HSN for a short period of about 20 seconds. The uv1 cell may serve as "the cluster egg counter", activated by a cluster of closely spaced egg-laying events and inhibiting HSN activity for a longer time of about 20 minutes. Together, these two pathways could produce the observed clustered temporal pattern by acting as negative regulators acting on different time scales