Reimers.dk

.NET, AJAX and Google APIs brought together
Welcome to Reimers.dk Sign in | Join | Help
in Search

Databound control

Last post 01-23-2010, 12:09 by jjrdk. 1 replies.
Sort Posts: Previous Next
  •  01-22-2010, 14:43 2966

    Databound control

    Hi,

    I've been struggling now for best part of two days with this and am comply stuck. If anyone can help me then I will post my finished code for the application for the benefit of others.

    Problem scenario:

    1. Draggable marker - when dragged it will centre the map
    2. Server side event gets a list of geo locations within a given radius
    3. Plot markers on a map based on the returned database values
    4. Display a databound control (grid view, list view, datalist, whatever) with database field values

    So far I have been able to achieve parts 1, 2 and 3.

    I have  got as far as databinding the grid view (I have tested this is happening in the code behind but I am unable to get it to render on the page).
    I have also tried using a side bar but am also unable to get this to render.

    My .cs code is below, any help would be immensely appreciated.

    protected void MarkerDragEnd(object sender, MarkerDraggedEventArgs e)
    {

    StringBuilder addAllOverlays = new StringBuilder();
            float distanceSearch = (float)Convert.ToDouble(lstSearchRadius.SelectedValue.ToString());
            DataSet dsParkingSpaces = dataRetrieval.getParkingSpacesForGoogle(e.To.Longitude, e.To.Latitude, distanceSearch);

            GoogleMarkerOptions mOpts = new GoogleMarkerOptions();
    mOpts.Draggable = false;
            for (int i = 0; i <= dsParkingSpaces.Tables[0].Rows.Count - 1; i++)
    {
    mOpts.Title = dsParkingSpaces.Tables[0].Rows[i]["PostCode"].ToString();
            GoogleLatLng latlngMarker = new GoogleLatLng(Convert.ToDouble(dsParkingSpaces.Tables[0].Rows[i]["Latitude"]), Convert.ToDouble(dsParkingSpaces.Tables[0].Rows[i]["Longitude"]));
            GoogleMarker mkr = new GoogleMarker(dsParkingSpaces.Tables[0].Rows[i]["ID"].ToString(), latlngMarker, mOpts);
            addAllOverlays.Append(e.Map.AddOverlay(mkr));
           }

    //PROBLEM CODE - I am binding the datagrid but it is not showing up on the page 

    grdTest.DataSource = dsParkingSpaces;
            grdTest.DataBind();

            //re-create the draggable marker
            GoogleMarker dMarker = new GoogleMarker("draggableMarker", new GoogleLatLng(e.To.Latitude, e.To.Longitude));
            dMarker.Options.Draggable = true;
            dMarker.Options.Title = "This control is cool!!!";
            dMarker.Options.UpdateAfterDrag = true;

            addAllOverlays.Append(e.Map.AddOverlay(dMarker));

            e.MapCommand = e.Map.ClearOverlays() + addAllOverlays.ToString() + GMap.PanTo(new GoogleLatLng(e.To.Latitude, e.To.Longitude));

        } 

  •  01-23-2010, 12:09 2969 in reply to 2966

    Re: Databound control

    I think the reason your grid is not updating is that it does not participate in the callback that happens when the dragend event is triggered. All map events (including dragend) make use of the ICallbackEventHandler to trigger serverside events.

    One of the shortcomings of the ICallbackEventHandler is that it returns a JavaScript command that does only what you decide. This is in fact what any basic AJAX call does, so it is to be considered a feature.

    So if you want your grid to update with the latest values you are going to have to include it in the flow somehow. I made the Sidebar control which is a basic table that displays your markers. It can also receive updates from serverside events (although I have to admit that it is a bit lacking).

    The short story is that you are either going to have to have your grid (not the map) inside an UpdatePanel and force an update of that or do some clientside DOM coding yourself. 

View as RSS news feed in XML