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

Discussion in 'ASP .Net' started by Andy B, Nov 15, 2008.

  1. Andy B

    Andy B Guest

    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.
     
    Andy B, Nov 15, 2008
    #1
    1. Advertising

  2. Andy B

    bruce barker Guest

    Re: Making a controls ID property inside a repeater controls ItemTemplatethe value of the ItemIndex?

    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)


    Andy B wrote:
    > 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.
    >
    >
     
    bruce barker, Nov 15, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bennett Haselton
    Replies:
    1
    Views:
    5,341
    Joe Fallon
    Sep 24, 2004
  2. Fred Dag
    Replies:
    1
    Views:
    2,029
    =?Utf-8?B?U2VyZ2V5IFBvYmVyZXpvdnNraXk=?=
    Jan 20, 2006
  3. Brad Baker

    Problem with Repeater.ItemIndex

    Brad Baker, Feb 25, 2007, in forum: ASP .Net
    Replies:
    5
    Views:
    912
    Steven Cheng[MSFT]
    Mar 1, 2007
  4. Oleg
    Replies:
    1
    Views:
    7,342
    Cowboy \(Gregory A. Beamer\)
    Mar 7, 2008
  5. Replies:
    0
    Views:
    192
Loading...

Share This Page