The NIV Student Bible explains:
David's prayer at the beginning of temple construction shows why he was a man after God's own heart. Despite all his achievements, he was deeply humble. He wanted glory to go to God, not Himself.
Here's the gist of the prayer from 1 Chronicles 29:
David praised the LORD in the presence of the whole assembly, saying,
Praise be to You, O LORD,
God of our father Israel,
from everlasting to everlasting.
Yours, O LORD, is the greatness and the power
and the glory and the majesty and the splendor,
for everything in heaven and earth is Yours.
Yours, O LORD, is the kingdom;
You are exalted as head over all.
Wealth and honor come from You;
You are the ruler of all things.
In Your hands are strength and power
to exalt and give strength to all.
Now, our God, we give You thanks,
and praise Your glorious name.
But who am I, and who are my people,
that we should be able to give as generously as this?
Everything comes from You,
and we have given You only what comes from Your hand.
As for all this abundance that we have provided
for building You a temple for Your Holy Name,
it comes from Your hand,
and all of it belongs to You.
I know, my God,
that You test the heart and are pleased with integrity.
All these things have I given willingly and with honest intent.
And now I have seen with joy
how willingly Your people who are here have given to You.
O LORD, God of our fathers Abraham, Isaac and Israel,
keep this desire in the hearts of Your people forever,
and keep their hearts loyal to You.
And give my son the wholehearted devotion
to keep Your commands, requirements and decrees.