2012-07-29 47 views
0
Protected Sub FormView1_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.DataBinding 

    Dim streetAddres As String = Nothing 
    Dim EventLabel As Label = FindControl("Event_locationLabel") 
    Dim findMap As GMap = FindControl("GMap1") 

    Dim GeoCode As GeoCode = Nothing 
    ' Get user typed text from text box 
    streetAddres = EventLabel.Text 
    ' pass your city name in the geo code request it return geo code 
    GeoCode = findMap.getGeoCodeRequest(streetAddres) 
    ' Add the geocode in 
    Dim gLatLng As New GLatLng(GeoCode.Placemark.coordinates.lat, GeoCode.Placemark.coordinates.lng) 
    ' Set center of map based on latitude and longitude coordinates 
    findMap.setCenter(gLatLng, 16, GMapType.GTypes.Physical) 
    Dim oMarker As New GMarker(gLatLng) 
    ' Bind that marker data in google map 
    findMap.addGMarker(oMarker) 

End Sub 

错误:如何在表单中将标签绑定到Google Map?

Object reference not set to an instance of an object.

调试的:停止线:streetAddres = EventLabel.Text

+0

EventLabel不存在Event_locationLabel的引用。 – Jones 2012-07-29 02:56:29

回答

0

问题是Event_locationLabel不是有效的控制ID。您需要检查页面以查看应该调用的内容。

如果由于某种原因阻止访问页面源,则可以打开Internet Explorer并按F12访问开发人员工具。这些对于识别(和调整)页面中的元素非常方便。

+0

非常感谢您的回复。我的Event_LocationLabel是从我的数据库中取得的标签,并且是一个地址。我试图从FormView中的标签地址加载googlemap – Alexis1992 2012-07-29 03:08:19

+0

标签如何添加到页面中?您正在尝试在页面中找到控件,但它不在那里,所以这可能是您添加控件的位置或您尝试访问它的位置的问题。 – 2012-07-29 03:10:25

+0

我放在aspx中,在formview中。第一个邮政编码是后面的代码。 再次感谢你 – Alexis1992 2012-07-29 03:18:18