Firstly, after your loop you pop the last element that has been pushed. Instead pop the element before entering the loop.
Secondly, handle the elements as you take them from the stack, not when you push them onto it.
Thirdly, to achieve the order you want, iterate the children nodes backwards (so smaller children will be on top of the stack):
public void dfs(int vertex)
{
int length = matrix.GetLength(0);
bool[] visited = new bool[length];
for (int k = 0; k < length; k++)
{
visited[k] = false;
}
Stack<int> vertexStack = new Stack<int>();
vertexStack.Push(vertex);
while (vertexStack.Count() != 0)
{
int tempVertex = vertexStack.Pop();
if (!visited[tempVertex])
{
visited[tempVertex] = true;
Console.Write((tempVertex) + " ");
for (int j = length - 1; j >= 0; j--)
{
if (matrix[tempVertex, j] == 1 && !visited[j])
{
vertexStack.Push(j);
}
}
}
}
}