With the popularization of electric vehicles (EVs), EV charging demand is becoming an important load in the building. Considering the mobility of EVs from building to building and their uncertain charging demand, it is of great practical interest to control the EV charging process in a microgrid of buildings to optimize the total operation cost while ensuring transmission security between the microgrid and the main grid. We consider this important problem in this article and make the following contributions. First, we formulate this problem as a Markov decision process (MDP) to capture the uncertain supply and EV charging demand in the microgrid of buildings. Besides reducing the total operation cost of buildings, the model also considers the power exchange limitation to ensure transmission security. Second, this model is reformulated within an event-based optimization (EBO) framework to mitigate the impact of large state and action space. A randomized parametric event-based control policy is proposed for the microgrid controller to determine the charge ratio for each building. Then, a selecting-to-charging principle is implemented for each building controller to determine the charge control of each EV in the building. Third, a constrained gradient-based policy optimization method is developed to find the optimal event-based control policy. Furthermore, an adjustment mechanism is also introduced to ensure transmission security during optimization. Numerical experiments are conducted to analyze the structure and the performance of the event-based control policy for EV charging in a microgrid of three buildings.