Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Trying to access a Repeater's HeaderTemplate controls from event fired in an ItemTemplate control

Trying to access a Repeater's HeaderTemplate controls from event fired in an ItemTemplate control

Scheduled Pinned Locked Moved ASP.NET
csharpdockerhelpquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Cyrilix
    wrote on last edited by
    #1

    I've got an ASP .NET webpage with the following structure:

    <asp:DataGrid ID="aGrid">
    <Columns>
    asp:TemplateColumn
    <ItemTemplate>
    <asp:Repeater ID="aRepeater">
    <HeaderTemplate>
    <asp:Label ID="aLabel" Text='<%# DataBinder.Eval(Container.DataItem, "SomeColumn") %>'></asp:Label>
    </HeaderTemplate>
    <ItemTemplate>
    <asp:TextBox ID="aTextBox" AutoPostBack="true" OnTextChanged="SomeEvent"></asp:TextBox>
    </ItemTemplate>
    </asp:Repeater>
    </ItemTemplate>
    </asp:TemplateColumn>
    </Columns>
    </asp:DataGrid>

    The problem I'm having is that I would like to access the data that is stored in the label aLabel in the OnTextChanged event. What I'm doing to achieve this purpose is:

    void SomeEvent(object sender, EventArgs e)
    {
    //Bind aRepeater to a certain data source in the ItemDataBound event of aGrid

    //Get reference to aRepeater
    //Parent gets you the RepeaterItem
    //Parent.Parent gets you the Repeater
    Repeater r = (sender as TextBox).Parent.Parent;
    
    //Assert that r.DataSource != null
    

    }

    My assertion, however, fails, and even if I get aLabel.Text, it ends up being an empty string, since r.DataSource is null (despite the fact that in the ItemDataBound event of aGrid, I already bound the repeater to a data source). After some debugging, I noticed that Repeater r is not the same repeater as the one that I bound in the ItemDataBound event of aGrid, but how could that be? In the ItemDataBound event of aGrid, I do the following... //e is DataGridItemEventArgs object in ItemDataBound event e.Item.FindControl("aRepeater") as Repeater; ...which I assume should be equivalent to... (sender as TextBox).Parent.Parent; Sorry for the long post.

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups