forum

Home / DeveloperSection / Forums / How to select a div in an asp.net repeater

How to select a div in an asp.net repeater

Lillian Martin 2081 21-Dec-2014

I have a div inside an asp.net repeater. I would like to handle an event on the client side when a user clicks on one of the div's. 

I've tried the onClick handler in the div (class="result"), but that doesn't seem to be firing. Is there another event I can tie this too? 

I also try creating an event handler using jquery, but I'm not sure how to select the element that the user clicks. Right now, I seem to be tying the event to all the div's. Any idea how I can fix the jquery selector for the a single div element? 

My repeater: 
<div id="search-results" >
    <asp:Repeater ID="pageResults" runat="server" ItemType="ArchiveViewer.Logic.PageResult"
        SelectMethod="GetSearchResults" OnItemDataBound="pageResults_ItemDataBound" >
             <ItemTemplate>
                <div class="result" data-pageid="<%#:Item.PageId %>" data-pageNumber="<%#:Item.Number %>"
                    onclick="resultSelected"  >
                        <div>
                            Page: <%#:Item.Number %>
                        </div> 
                        <div>
                          <asp:Label ID="lblSearchResult" runat="server" ></asp:Label>
                        </div>                                       
                 </div>
             </ItemTemplate>
     </asp:Repeater>
</div>

And my jquery scripts: 

$('#search-results div').click(function (e) {
        $(this).removeClass('active');
        $(this).addClass('active');
        // this is setting the active class for all the div's in the repeater...
});
 
var resultSelected = function () {
        // this is not working
};


Updated on 22-Dec-2014

Can you answer this question?


Answer

2 Answers

Liked By