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

  • Thread starter Thread starter Andy B
  • Start date Start date
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.
 
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)
 
Back
Top