Forums

 
  Support Forum  Modules  Engage: Locator  Convert distance from Mile to KM
Previous Previous
 
Next Next
New Post 2/13/2009 12:35 PM
  yanickmiron
5 posts
No Ranking


Convert distance from Mile to KM 

Hi,

I've installed the locator module for a client that have stores in canada. The actual distance is calculated in miles but in canada the distance is calculated in km. Is there something I can do to solve this problem. I'm not an expert in ASP but must have a way to convert the following asp label in MainDisplay.ascx file?

<asp:Label ID="lblLocationsGridDistance" runat="server"  />

What  I yould like to do is the following (Instead of printing the default "X.XX Miles" string):

1) Split de X.XX from Miles

2) Convert (left part) into an integer

3) multiply the integer by 1.6

4) Convert the result into a string and append to it the following string " Km"

I think that it's something possible but I don't know how to do it in asp.

Does anyone have a better solution?

Thanks.

 
New Post 2/13/2009 1:27 PM
  Brian Dukes
498 posts
4th Level Poster


Re: Convert distance from Mile to KM 
Modified By Brian Dukes  on 2/13/2009 2:31:07 PM)

We suggest that you avoid altering the files we provide, it can make it hairy if something else breaks, and definitely makes upgrading a pain.

However, that said, I was intrigued by this question and have written a (completely unsupported) solution that seems to work for me.  This is based on that latest Locator (1.4), which it looks like you don't have yet (based on the name of the label).  Add this to the bottom of MainDisplay.ascx and see if that does what you want.

<script runat="server">
protected override void OnInit(EventArgs e)
{
    this.PreRender += this.Page_PreRender;
    base.OnInit(e);
}
private void Page_PreRender(object sender, EventArgs e)
{
    foreach (RepeaterItem item in this.LocationsListRepeater.Items)
    {
        Label locationsGridDistanceLabel = item.FindControl("LocationsGridDistanceLabel") as Label;
        if (locationsGridDistanceLabel != null && locationsGridDistanceLabel.Visible)
        {
            int firstSpaceIndex = locationsGridDistanceLabel.Text.IndexOf(' ');
            string distanceLabel = locationsGridDistanceLabel.Text.Substring(firstSpaceIndex);
            
            double distanceInMiles;
            if (double.TryParse(locationsGridDistanceLabel.Text.Substring(0, firstSpaceIndex), 
                                NumberStyles.Float, 
                                CultureInfo.CurrentCulture, 
                                out distanceInMiles))
            {
                locationsGridDistanceLabel.Text = (distanceInMiles * 1.6).ToString(CultureInfo.CurrentCulture)
                                                  + distanceLabel;
            }
        }
    }
}
</script>

This will accomplish multiplying the values by 1.6.  I would suggest sticking to altering the resource files to change the label from Miles to KM.

Hope it helps,


Brian Dukes
Engage Software
St. Louis, MO
314.966.4000

The leading provider of DotNetNuke support, training and custom module development.
 
New Post 3/19/2009 9:09 AM
  yanickmiron
5 posts
No Ranking


Re: Convert distance from Mile to KM 

Thanks.

It works.

 
Previous Previous
 
Next Next
  Support Forum  Modules  Engage: Locator  Convert distance from Mile to KM

Purchase

Please click here to buy now.
Payment will be processed via credit card or PayPal.

Please click here to buy now.
Payment will be processed via credit card or PayPal.

Test Drive!

Want to find out how it works? Visit our demo site to see the modules in actions!

Want to find out how it works? Visit our demo site to see the modules in actions!

Subscribe

Sign up for our newsletter and get the latest product updates!

Sign up for our newsletter and get the latest product updates!

Online Support

Powered by DotNetNuke