Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Latitude/longitude input control: an ASP.NET 2.0 server control

0.00/5 (No votes)
6 Mar 2006 1  
Latitude longitude input control - as ASP.NET 2.0 server control.

Introduction

This code drop is part of a smash and grab series. If you're in a rush, you can just grab this code and insert it into your application, no understanding is required. When you have some time (ya, right), you may want to review the source code.

Background

I recently needed to enter latitude and longitude information into a GridView control, and so I wrote this ASP.NET 2.0 server control. The top part of the graphic shows the various input formats which you can toggle between using the spinners to the right. The bottom part shows the control in use in a FormView.

Using the code

  • Download the project, unzip it to somewhere on your hard disk.
  • Create a new ASP.NET project.
  • Create a Bin folder for the project.
  • Select Tools > Choose toolbox items.
  • Navigate to the unzip folder and select the DLL.
  • This new server control now appears in the toolbox (usually) under General.
  • Drag an instance of it onto Default.aspx.
  • Enjoy.

The control supports these properties:

  • LatitudeLongitude: Choose whether the control is to contain a latitude or a longitude value.
  • InputFormat: There are three common formats for latitude/longitude: Degrees (with a fractional degree part), Degrees and Minutes (with a fractional minute part), and Degrees, Minutes and Seconds. Use this property to set the default display format. At run time, you can choose a different format using the spin control.
  • ReadOnly: Set when you don't want to allow editing.

    You will set ReadOnly to true in the "ItemTemplate" of the GridView template for this control. You will set ReadOnly to false in the "EditItemTemplate" of the GridView template for this control.

Points of Interest

You must bind the Text property of the control to a floating point database type. You will also notice that there is no JavaScript or images that you need to add to your project. These are all imbedded in the DLL using WebResources. I have written an article on using WebResources, here at CodeProject. Search using the keywords redux WebResourse.

Conclusions

There you go, a free ASP.NET 2.0 Latitude/Longitude control that suits my needs and hopefully yours.

SmashGrab / Redux series

I have recently started two series of articles here at CodeProject. Smash&Grab is intended as a series of short articles on one specific code technique. Redux is intended as a series of longer articles which attempt to reduce a complicated topic (like GridView) into its basic constituent parts and show that once you have all the information, it wasn't really that hard after all. To find the Smash&Grab articles, search for the keyword SmashGrab. To find the Redux articles, search for keyword Redux. I welcome any contributions to either series, but please follow the guidelines when submitting articles to either.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here