Recovering Findcontrol from Parent Peater in Child Remaster event

Asked

Viewed 865 times

3

I’m having a hard time getting a field of my parent Peater at the click of my linkbutton inside another Peater (son).

My Parent contains the report code and other information and my Parent contains the dates of that report. When the user clicks on a certain date I need to take this code from the parent and tbem take the date to do the process. But I can’t do either.

Follows my html:

<asp:Repeater ID="Repeater1" OnItemDataBound="rptRelatorioFavoritos_ItemDataBound" runat="server">
<HeaderTemplate>
    <table>
        <tr class="titulo">
            <th colspan="4">Favoritos</th>
        </tr>
        <tr>
            <th width="5%" class="td_titulo">Relatório</th>
            <th width="10%" class="td_titulo">Assunto</th>
            <th width="20%" class="td_titulo">Descrição</th>
            <th width="25%" class="td_titulo">Clique na Data Desejada</th>
        </tr>
</HeaderTemplate>
<ItemTemplate>
    <tr class="tr_branco">
        <td class="td_branco">
            <asp:ImageButton CommandArgument='<%#DataBinder.Eval(Container.DataItem, "CodRelatorio")%>' ID="imgbFavorito" ImageUrl="~/Content/imgs/BookDel.gif" OnCommand="imgbFavorito_Command" runat="server" ToolTip="Remover do seus favoritos?" />
            &nbsp;&nbsp;<asp:Label ID="lblCodRelatorio" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "CodRelatorio")%>' />
        </td>
        <td class="td_branco">
            <asp:Label ID="lblAssunto" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "AssuntoRelatorio")%>'></asp:Label>
        </td>
        <td class="td_branco">
            <asp:Label ID="lblDescricao" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "DescricaoRelatorio")%>'></asp:Label>
        </td>
        <td class="td_branco">
            <asp:Label ID="lblLocal" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "LojaRelatorio")%>'></asp:Label>

            <asp:Repeater ID="rptRelFilho" OnItemDataBound="rptRelFilho_OnItemDataBound" OnItemCommand="rptRelFilho_OnItemCommand" runat="server">
                <ItemTemplate>
                    <asp:LinkButton ID="lkbDataRelatorio" runat="server"><%#DataBinder.Eval(Container.DataItem, "DataRelatorio")%></asp:LinkButton>&nbsp;
                </ItemTemplate>
            </asp:Repeater>
            <asp:LinkButton ID="lkbDataRelatorio02" runat="server">...</asp:LinkButton>
        </td>
    </tr>
</ItemTemplate>
<FooterTemplate>
    </table>
</FooterTemplate>

My . Cs is like this:

protected void rptRelFilho_OnItemCommand(object source, RepeaterCommandEventArgs e)
    {

        var itensPai = e.Item.Parent.Parent;
        var lblCodRel = (Label)itensPai.FindControl("CodRelatorio");


        var link = (LinkButton)e.Item.FindControl("DataRelatorio");
        string v = link.Text;


    }

Follow the image of the report so you have a sense of what I’m trying to do. inserir a descrição da imagem aqui

1 answer

1

by what I understood the whole question is to capture the value of a control outside the Reset child but inside the Reset parent? Correct?

See the example I built following this idea:

<asp:Repeater ID="rptPai" runat="server" OnItemDataBound="rptPai_ItemDataBound">
        <HeaderTemplate>
            <table>
                <thead>
                    <th>Código</th>
                    <th>Descrição</th>
                    <th>Clique na data desejada</th>
                </thead>
        </HeaderTemplate>
        <ItemTemplate>
            <tr>
                <td><%# Eval("Codigo") %></td>
                <td><%# Eval("Descricao") %></td>
                <td>
                    <asp:HiddenField id="hdfCodigoRelatorio" runat="server" Value='<%# Eval("Codigo") %>'/>
                    <asp:Repeater ID="rptFilho" runat="server" OnItemCommand="rptFilho_ItemCommand">
                        <ItemTemplate>
                            <asp:LinkButton ID="lkbDataRelatorio" runat="server">
                                <%# this.GetDataItem().ToString() %>
                            </asp:LinkButton>&nbsp;
                        </ItemTemplate>
                    </asp:Repeater>
                </td>
            </tr>
        </ItemTemplate>
        <FooterTemplate>
            </table>
        </FooterTemplate>
    </asp:Repeater>

Note that just before Repeater son, called rptFilho, I placed a Hiddenfield that receives the code of the report from that line. It is this control that I will access to get the code:

    protected void rptPai_ItemDataBound(object sender, RepeaterItemEventArgs args)
    {
        if (args.Item.ItemType == ListItemType.Item || args.Item.ItemType == ListItemType.AlternatingItem)
        {
            Repeater childRepeater = (Repeater)args.Item.FindControl("rptFilho");
            HiddenField hdfCodigoRelatorioPai = (HiddenField)args.Item.FindControl("hdfCodigoRelatorio");

            childRepeater.DataSource = CarregarDatas(Convert.ToInt32(hdfCodigoRelatorioPai.Value));
            childRepeater.DataBind();
        }
    }

In the Itemdatabound of the parent Peater I took the code and use to fill in the dates of the child Peater. By clicking on one of the rptFilt dates, the Itemcommand event is called:

    protected void rptFilho_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        var itensPai = e.Item.Parent.Parent;
        HiddenField hdfCodigoRelatorioPai = (HiddenField)itensPai.FindControl("hdfCodigoRelatorio");

    }

See above that capturing the Father’s items is the same as how you were doing, and just give a findControl to bring the control you want. I did a test and the value of the report code is returned smoothly.

inserir a descrição da imagem aqui

This is just one way to do, in the Itemdatabound of the Peater parent you could already pass the report code and play it to the Peater child as well.

I hope I have been clear. Any doubt speaks there. :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.