This is the kind of thing I see a lot of youner Grammarians struggle with. Dialogue can be a tricky thing at times because its rules for punctuating differ just a bit from punctuating normal prose and may seem strange at times. However, I'm going to attempt to make it feel natural by explaining why it is the way that it is.
Here's an example to get us started...
Incorrect: “Hello.” She greeted.
Correct: “Hello,” she greeted.
Now, the first is incorrect because "she greeted" is a continuation of "Hello," and by putting a period at the end of "Hello" one cuts "she greeted" off from "Hello" when they want to be connected. The second is correct because the comma replaces the period and allows "Hello" and "she greeted" to work together. The "s" in "she" is also lowercased because it is technically located in the middle of the sentence. (This only applies where a period would be used. To find out what to do when the quoted phrase requires a question mark or exclaimation point please read on. Also, remember that punctuation always goes inside the quotes and not outside.)
Incorrect: “How are you?” He asked.
Correct: “How are you?” he asked.
In the case of a question within quotes, a comma cannot end the quotes because it does not signal reader to raise their voice at the end like one would do when asking a question. Therefore, the questions in quotes must end in a question mark. However, the "he asked" portion of the sentence is still working with "How are you?" so the "h" in "he" needs to be lowercase. (This is one of those strange rules that may feel unnatural when writing, but it is grammatically correct. In addition, the same rules would apply to the use of an exclaimation point.)
Incorrect: “I wondered about that,” he turned away from her.
Correct: “I wondered about that.” He turned away from her.
This is an example of an instance where the quoted sentence and the sentence outside the quotes are not working together. They are two complete and seperate sentences. Therefore, the statement in quotes ends with a period (or a question mark or exclaimation) and the statement outside the quotes is capitalized.
I hope this made sense and is something many people can learnt oapply in their work. If anything is confusing, please feel free to ask questions.