locked
how to get Label's client id which is in List View, to be used in Javascript RRS feed

  • Question

  • User2015884762 posted


    Hi,
    How do I get the listview item's ID, I am not able to use the clientidmode = static as it renders all with the same ID. My Javascript is in a separate page.


    Friday, November 15, 2019 9:57 AM

Answers

  • User1535942433 posted

    Hi callykalpana,

    As far as I know, asp.net web form will add the parent control id as the part of ID name in the lable, so you couldn't find the control ID directly.

     I suggest you could try to use jquery instead of js to acheive your requirement. Since it contains the selector which could directly select the html element by part of ID. E.g: [id*='StopReason_TextLabel']

    You could directly refer the jquery by using online CDN.

    Jquery selectors: https://api.jquery.com/category/selectors/

    More details about how to use it ,you could refer to below codes;

     <script>
           $(document).ready(function(){
               $("[id*='StopReason_TextLabel']").each(function () {
                   alert($(this).attr("id"));
               });
           })
        </script>
    
    
     <div>
                    <div id="panel">
                            <asp:ListView ID="ListView1" runat="server" GroupItemCount="7">
                                <AlternatingItemTemplate>
                                    <td runat="server" class="tile_alternate">
                                        <asp:Label ID="StopReason_TextLabel" name="testlabel" runat="server" Text='<%# Eval("First") %>' />
                                        <asp:Label ID="StopReason_IDLabel" runat="server" Text='<%# Eval("Third") %>' Visible="false" />
    
                                    </td>
                                </AlternatingItemTemplate>
                                <EmptyDataTemplate>
                                    <table runat="server" class="tile_empty">
                                        <tr>
                                            <td>No data was returned.</td>
                                        </tr>
                                    </table>
                                </EmptyDataTemplate>
                                <EmptyItemTemplate>
                                    <td class="tile_empty" runat="server" />
                                </EmptyItemTemplate>
                                <GroupTemplate>
                                    <tr id="itemPlaceholderContainer" runat="server">
                                        <td id="itemPlaceholder" runat="server"></td>
                                    </tr>
                                </GroupTemplate>
                                <ItemTemplate>
                                    <td runat="server" class="tile_notalternate">
                                        <asp:Label ID="StopReason_TextLabel" runat="server" Text='<%# Eval("First") %>' />
                                        <asp:Label ID="StopReason_IDLabel" runat="server" Text='<%# Eval("Third") %>' Visible="false"/>
                                    </td>
                                </ItemTemplate>
                                <LayoutTemplate>
                                    <table runat="server" >
                                        <tr runat="server">
                                            <td runat="server">
                                                <table id="groupPlaceholderContainer" runat="server" class="tiletable">
                                                    <tr id="groupPlaceholder" runat="server">
                                                    </tr>
                                               </table>
                                            </td>
                                        </tr>
                                    </table>
                                </LayoutTemplate>
                                <SelectedItemTemplate>
                                    <td runat="server">StopReason_Text:
                                        <asp:Label ID="StopReason_TextLabel" runat="server" Text='<%# Eval("First") %>' />
                                        <br />StopReason_ID:
                                        <asp:Label ID="StopReason_IDLabel" runat="server" Text='<%# Eval("Third") %>' />
                                        <br /></td>
                                </SelectedItemTemplate>
                            </asp:ListView>
                        </div>
                    </div>
                    <h2>Animated Modal with Header and Footer</h2>
                    <!-- Trigger/Open The Modal -->
                    <button id="myBtn">Open Modal</button>
                    <!-- The Modal -->
                    <div id="myModal" class="modal">
                        <!-- Modal content -->
                        <div class="modal-content">
                            <div class="modal-header">
                                <div class="b"><h2>Modal Header</h2></div>
                                <span class="closemodalX">&amptimes</span>
                            </div>
                            <div class="modal-body">
                                <p>Some text in the Modal Body</p>
                                <p>Some other text...</p>
                            </div>
                            <div class="modal-footer">
                                <div class="b"><h3>Modal Footer</h3></div>
                            </div>
                        </div>
                    </div>

    Result:

    Best Regards,

    Yijing Sun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 18, 2019 9:59 AM