locked
how-to-get-dropdownlist-and-label-ids-from-listview-to-javascript RRS feed

  • Question

  • User616860969 posted

    <script>

    function getmodel()

    {
    var SelectedText = DropdownList.options[DropdownList.selectedIndex].text;
    var lblunitcost = document.getElementById('<%=lblunitcost.ClientID %>');
    var sValue = SelectedText;
    lblunitcost.innerHTML = sValue;
    }

    </script>

    <div >

    <asp:ListView ID="lstViewProducts" runat="server" GroupItemCount="1" OnItemDataBound="lstViewProducts_ItemDataBound" DataKeyNames="ProductID" >
    <grouptemplate>
    <div id="itemPlaceholderContainer" runat="server" > 
    <div id="itemPlaceholder" runat="server"></div>
    </div>
    </grouptemplate>
    <itemtemplate>
    <span class="unit-cost">Rs.<asp:Label ID="lblunitcost" runat="server"></asp:Label></span> 
    <asp:DropDownList ID="ddlmodel" runat="server" AutoPostBack="true" onchange="getmodel();">
    </asp:DropDownList>


    </itemtemplate>

    <layouttemplate>
    <div>
    <div id="groupPlaceholderContainer" runat="server">
    <div id="groupPlaceholder" runat="server"></div>
    </div>
    </div>
    </layouttemplate>

    </asp:ListView>

    </div>

    Friday, August 19, 2016 3:41 AM

Answers

  • User-1496088595 posted

    you can easily get the dropdownlist and labels ids by using jquery selectors 

    please refer below snippet.

    $('[id$=lstViewProducts]').find('label, select').each(function(index){
       
         var self = $(this);
    
         // To get the type of element weather it is label/dropdown
         console.log(self.is("label"));
         console.log(self.is("select"));
    
         //To get the id of element.
         console.log($(this).attr('id'));
    });
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, August 19, 2016 4:46 AM

All replies

  • User-1496088595 posted

    you can easily get the dropdownlist and labels ids by using jquery selectors 

    please refer below snippet.

    $('[id$=lstViewProducts]').find('label, select').each(function(index){
       
         var self = $(this);
    
         // To get the type of element weather it is label/dropdown
         console.log(self.is("label"));
         console.log(self.is("select"));
    
         //To get the id of element.
         console.log($(this).attr('id'));
    });
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, August 19, 2016 4:46 AM
  • User616860969 posted

    thankyou sir,

    but i am not good in jquery here 

    label  means  just label or i will write labelid and like that dropdown

    Friday, August 19, 2016 5:15 AM
  • User-1496088595 posted

    no it just a label and select which are html controls not an id, the controls which we are using on aspx page like asp:label, asp:dropdown finally rendered it into plain html controls

    Friday, August 19, 2016 5:27 AM
  • User616860969 posted

    Thanks you
    Friday, August 19, 2016 5:36 AM
  • User616860969 posted

    its working

    Friday, August 19, 2016 12:56 PM