Whenever any prisoner confined in a jail established and maintained by the sheriff in another county, is tried for any offense committed in such jail or for escaping or attempting to escape therefrom, the venue shall be in the county establishing and maintaining such jail and the costs shall be charged against that county.