Div inside a Repeater
Im trying to access a div from my repeater by pressing a button which is in the repeater too the div is in display: none; the button has a jquery script which comes in play OnClientClick.
heres a sample of the HTML:
<asp:Repeater runat="server" ID="rptrPics" OnItemDataBound="rptrPics_ItemDataBound" OnItemCommand="rptrPics_ItemCommand">
<ItemTemplate>
<asp:Button runat="server" ID="showDiv" OnClientClick="$('div[imageId=' + imageId + ']').slideToggle(); return false; />
<div runat="server" id="hiddenDiv" style="display: none;">
SOME CODE
</div>
</ItemTemplate>
</asp:Repeater>
now the imageId is an Attribute which i set in the repeaterBinder
hiddenDiv.Attributes.Add("imageId", imgData.Pr开发者_Python百科oductId.ToString());
showDiv.Attributes.Add("imageId", imgData.ProductId.ToString());
nothing seems to work need advices.
You forget use this.getAttribute(name) in OnClick expression
OnClientClick="$('div[imageId=' + this.getAttribute(imageId) + ']').slideToggle(); return false; />
function slideToggle(button) {
$(button).next("div.hiddenDiv").slideToggle();
return false;
}
<asp:Repeater runat="server" ID="rptrPics">
<ItemTemplate>
<asp:Button runat="server" ID="showDiv" OnClientClick="return slideToggle(this);" Text="Show" />
<div runat="server" class="hiddenDiv" style="display:none;" >
SOME CODE
</div>
</ItemTemplate>
精彩评论