#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    2
    Rep Power
    0

    Getting ListView, <ul> <li> <asp:label> values into a javascript array.


    I have been working on this for two days. I have managed to get my array working, it is filling with my database objects, but, I cannot extract the values of my <li> elements, which are made up of a few hyperlimks, and labels(with ids). My array is being filled with elements, but the values arent getting pulled out. I have a watch set on my listview(healthCenters), which has an <ul>(myList) in it. The innerHTML has this as the value when I look at it in my Watch window:
    <a id="healthCenters_hlCenterName_0" href="searchResponse.aspx?LocationID=253">Philadelphia District health Center #10</a>

    The name is a hyperlink in a <li> element of my <ul>.
    How do I get to this value? Or do I have my values buried too deep in the HTML for my array to extract? I have labels in the <li> elements of my <ul> that make up my listView. Here is the value of one of the labels from the watch window:

    Type of Center: <span id="healthCenters_lblTypeofCenter_0">FQHC</span>

    The value I need is "FQHC". The value of the outterText is:
    Type of Center: FQHC.

    For the outterHTML on the CenterName, I got this:
    <li><a id="healthCenters_hlCenterName_0" href="searchResponse.aspx?LocationID=253">Philadelphia District health Center #10</a></li>

    Here is my original code:
    function AddData() {
    var locationDB = document.getElementById('myList').getElementsByTagName('li');
    var locationAry = [];

    // fetch locations returned by database
    var items = locationDB;
    if (items.length == 0) {
    clearMap();
    return;
    }
    // loop through found locations in the database
    for (var i = 0; i < items.length; i++) {
    var locationid = items[i].getAttribute('lblLocationID');
    var healthCenterName = items[i].getAttribute('CenterName');
    var typeofCenter = items[i].getAttribute('TypeofCenter');
    var address = items[i].getAttribute('Address');
    var city = items[i].getAttribute('City');
    var state = items[i].getAttribute('State');
    var zipCode = items[i].getAttribute('ZipCode');
    var phone = items[i].getAttribute('PhoneNumber');
    var url = items[i].getAttribute('Website');
    var services = items[i].getAttribute('PatientServices');
    var distance = parseFloat(items[i].getAttribute('DistanceMiles'));
    var location = new Microsoft.Maps.Location(parseFloat(items[i].getAttribute('Lat')), parseFloat(items[i].getAttribute('Long')));
    var description = address + '<br/>' + city + '<br/>' + state + '<br/>' + phone + '<br/>' + url + '<br/>' + distance;
    // push location to array for use in map viewing
    locationAry.push(location);
    }
    var pin1 = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(location));
    pin1.Title = healthCenterName;
    pin1.Description = description;
    Microsoft.Maps.Events.addHandler(pin1, 'click', displayInfobox);
    dataLayer.push(pin1);

    }
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    50
    Rep Power
    2
    Your post is confusing.

    You want to get the value of an element but you didn't post your HTML.

    Can't you just provide ids to the elements and getElementById('').value?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    2
    Rep Power
    0
    Here is the HTML. I want to get the values of the asp: controls that are contained in my <li> elements in my <ListView>

    <asp:ListView ID="healthCenters" runat="server" DataKeyNames="CenterName,LocationID,Lat,Long">
    <LayoutTemplate >
    <ul id="myList">
    <asp:PlaceHolder ID="itemPlaceholder" runat="server" />
    </ul>
    </LayoutTemplate>
    <ItemTemplate >
    <li><asp:HyperLink ID="hlCenterName" runat="server" Text='<%# Eval("CenterName") %>' NavigateUrl='<%# Eval("LocationID", "searchResponse.aspx?LocationID={0}") %>' ></asp:HyperLink></li>
    <li style="list-style:none">Type of Center: <asp:Label ID="lblTypeofCenter" runat="server" Text='<%# Eval("TypeofCenter") %>' /></li>
    <li style="list-style:none"><asp:Label ID="lblAddress" runat="server" Text='<%# Eval("Address") %>' /></li>
    <li style="list-style:none"><asp:Label ID="lblCity" runat="server" Text='<%# Eval("City") %>' /> , <asp:Label ID="lblState" runat="server" Text='<%# Eval("State") %>' /></li>
    <li style="list-style:none"><asp:Label ID="lblZipCode" runat="server" Text='<%# Eval("ZipCode") %>' /></li>
    <li style="list-style:none">Phone:<asp:Label ID="lblPhoneNumber" runat="server" Text='<%# String.Format("{0###) ###-####}",Convert.ToInt64(Eval("PhoneNumber"))) %>' /></li>
    <li style="list-style:none"><asp:HyperLink ID="webSite" runat="server" NavigateUrl='<%# Eval("Website") %>' Text='<%# Eval("Website") %>'>HyperLink</asp:HyperLink></li>
    <li style="list-style:none">Patient Services: <asp:Label ID="lblPatientServices" runat="server" Text='<%# Eval("PatientServices") %>' /></li>
    <li style="list-style:none">Distance: <asp:Label ID="lblRadius" runat="server" Visible="True" Text='<%# String.Format("{0:0.##}", Eval("DistanceMiles")) + " " + "miles." %>' /></li>
    <li style="list-style:none"><asp:Label ID="lblLocationID" runat="server" Visible="false" Text='<%# Eval("LocationID") %>' /></li>
    <li style="list-style:none"><asp:Label ID="lblLat" runat="server" Visible="False" Text='<%# Eval("Lat") %>' /><asp:Label ID="lblLng" runat="server" Visible="False" Text='<%# Eval("Long") %>' /></li>
    <br />
    </ItemTemplate>
    </asp:ListView>

IMN logo majestic logo threadwatch logo seochat tools logo