Starting with the edge passing through 3 vertices, we have a couple of different possibilities. Give each vertex/asterix numbers like:
1 2 3
4 5 6
7 8 9
If we place the longest side of the triangle along the edge of the grid, e.g. passing through the vertices $1, 2$ and $3$, we have $4$ different possibilities when choosing the third corner (I'm ignoring vertices $7$ and $9$ here, since these triangles would be counted several times otherwise). There are $4$ such edges giving us $16$ possible triangles.
If we place the longest side along the horizontal axis, we can choose $6$ different vertices. The same applies for the vertical axis, which gives us an additional $12$ triangles.
Finally, the longest side, can be placed on a diagonal axis (e.g. through $1,5,9$) where we have $6$ possible choices (notice that we get the triangles we ignored in the first case), and there are $2$ such diagonal axes. We therefore have another $12$ possible triangles.
In total we have: $16+12+12=40$ possible configurations.