0

I'm trying to get the (div id="imgGallery" runat="server") element from nested Listview to modify the class name programatically.

<asp:ListView ID="ListView1" runat="server" ItemPlaceholderID="itemPlaceHolder1" onitemdatabound="ListView1_ItemDataBound">
<ItemTemplate>
    <asp:Label ID="VersionId" runat="server" Text='<%# Eval("VersionId") %>' Visible="false" />
    <asp:Label ID="MenuContent" runat="server" Text='<%# Eval("ContentText") %>' />
    <br />
    <asp:ListView ID="ListView2" runat="server" ItemPlaceholderID="itemPlaceHolder2">
        <ItemTemplate>
            <div id="imgGallery" class="images" runat="server">
                <asp:Image ID="Image1" ImageUrl='<%# Eval("ImageUrl") %>' runat="server" ToolTip="Text" />
            </div>
        </ItemTemplate>
        <LayoutTemplate>
            <asp:PlaceHolder runat="server" ID="itemPlaceHolder2"></asp:PlaceHolder>
        </LayoutTemplate>
    </asp:ListView>
</ItemTemplate>
<LayoutTemplate>
    <asp:PlaceHolder runat="server" ID="itemPlaceHolder1"></asp:PlaceHolder>
</LayoutTemplate>
<ItemSeparatorTemplate>
    <br />
    <hr />
    <br />
</ItemSeparatorTemplate>

on my code behind I tried the code below which doesn't work... and I tried different ways but can't find solution.

    ListView listView2 = (ListView)ListView1.FindControl("ListView2");
HtmlGenericControl mydiv = (HtmlGenericControl)listView2.FindControl("imgGallery");
mydiv.Attributes.Clear();
3
  • On which event you are trying to find that div ?? Commented Aug 1, 2012 at 6:18
  • The ListView is inside a tab, when I move from tab0 to tab1 I need to remove the class attribute from div element. Commented Aug 1, 2012 at 6:25
  • I can do it without listview. Commented Aug 1, 2012 at 6:27

1 Answer 1

1

You sholuld work with inner element of databound controls on databinding stage or iterating through row collection (called databind method before)

Sign up to request clarification or add additional context in comments.

5 Comments

The template'ed controls in the ASP.NET markup can be accessed after their Init event, which is called when the template (and thus the markup) is "instantiated". It doesn't directly align with data-binding (but it could be the result of it), but is a useful concept nevertheless ..
So that's the only way? there's no way to get the div element directly?
@user1567683 See my comment about Init (of controls inside..)
I'm sorry pst, I'm very new at this (I started 2 months ago). Do you know a link or could you give me a sample? I really appreciate that you reply
i use only that way. And cann't figure it out how to get access to template markup object without creating custom control inherited to ListView. Maybe Pst will provide a bit of code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.