You may have to import your .x model into a specialist program such as LithUnwrap (google it), and create the texture through that.
I can't tell you what to do from there, because I can't remember, but there should be a few tutorials around for you.
After you've made your texture (correct me if I'm wrong), you should just be able to load the object into your code, and as long as the texture is in the same folder as the object, the .X file shouls automatically detect and use it, without the need for you to apply the texture through code.
Hope that helps