Making a controls ID property inside a repeater controls ItemTemplate the value of the ItemIndex?

A

Andy B

I have a repeater control with an ItemTemplate inside of it. In the
ItemTemplate, I have a div with a link that calls a javascript function to
make an asp:panel control visible or invisible. I need to make the ID of the
panel equal to this databinding expression:
"d<%# DataBinder.Eval(Container, "ItemIndex") %>" Any ideas how to do this?
I keep getting errors about the expression is too complex for the ID
attribute, it is not a valid identifier, if the value is inclosed in quotes,
they must match and so on.
 
B

bruce barker

you have two issues.

1) you can not force the rendered id of a control in repeater.
2) setting a property value to a binding expression requires the value
only be the expression

try:


<script type="text/javascript">
function doit(e) {
e = document.getElementById(e);
e.style.display = e.style.display == 'block' ? 'none' : 'block';
}
</script>
<asp:Repeater ID="rpt" runat="server" >
<ItemTemplate>
<div>
<asp:HyperLink runat="server"
Text="click me"
NavigateUrl='<%# "javascript:doit(\""
+ Container.FindControl("p").ClientID
+ "\");" %>'
/>
</div>
<asp:panel ID="p" runat="server" style="display:none;">
hello
</asp:panel>
</ItemTemplate>
</asp:Repeater>

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top