Link to home
Start Free TrialLog in
Avatar of sesurb
sesurb

asked on

nested repeater - access parent data or fields

ASP.Net - VB

I have a repeater nested within another repeater. It is a questionnaire repeater and it holds questions in the parent repeater and possible answers in the child. In the Footer of the child repeater I have the ability to add new possible answers. The problem is when the button is clicked to add an answer I do associate it with the parent question. i can't seem to find a way to access the parent data or a field in the parent question role that will give me the id of the question. Can anyone help me out. I will post what my repeater looks like right now. I have been able to succesfully trap the itemcommand event which it seems people have a lot of trouble doing, but just can't seem to grab the data of the parent question on the itemcommand event.

<asp:repeater id="parentRepeater" runat="server">
                                                                                    <HeaderTemplate>
                                                                                          <table border="1" cellpadding="0" cellspacing="0" rules="none" frame="border" width="100%">
                                                                                                <tr bgcolor="#99cc66">
                                                                                                      <td width="50%"><strong>Question</strong></td>
                                                                                                      <td width="25%"><strong>Type</strong></td>
                                                                                                      <td width="25%"></td>
                                                                                                </tr>
                                                                                    </HeaderTemplate>
                                                                                    <itemtemplate>
                                                                                          <tr>
                                                                                                <td><%# DataBinder.Eval(Container.DataItem, "QQ_Question") %><asp:Label Runat=server ID="lblHidQQID" Visible=False text='<%# DataBinder.Eval(Container.DataItem, "QQ_ID") %>'></asp:Label></td>
                                                                                                <td><%# DataBinder.Eval(Container.DataItem, "QQ_Type") %></td>
                                                                                                <td><asp:Button id="btnQuestionRemove" Runat="server" Text="Remove Question" Font-Size="7"></asp:Button></td>
                                                                                          </tr>
                                                                                          <asp:repeater id="childRepeater" runat="server" OnItemCommand="eventRepeater_ItemCommand" OnItemDataBound="eventRepater_ItemDataBound" EnableViewState=True datasource='<%# Container.DataItem.Row.GetChildRows("myrelation")%>'>
                                                                                                <HeaderTemplate>
                                                                                                      <tr bgcolor="#ffffe4">
                                                                                                            <td></td>
                                                                                                            <td><strong>Answer Choice</strong></td>
                                                                                                            <td></td>
                                                                                                      </tr>
                                                                                                </HeaderTemplate>
                                                                                                <itemtemplate>
                                                                                                      <tr bgcolor="#ffffe4">
                                                                                                            <td>
                                                                                                                  <asp:Label ID="lblhidQCID" Runat=server Visible=False text='<%# Container.DataItem("QC_ID") %>'>
                                                                                                                  </asp:Label>
                                                                                                                  <asp:Label ID="lblhidQQID" Runat=server Visible=False text='<%# Container.DataItem("QC_Question")%>'>
                                                                                                                  </asp:Label>
                                                                                                            </td>
                                                                                                            <td><%# Container.DataItem("QC_Answer") %></td>
                                                                                                            <td>
                                                                                                                  <asp:Button id="btnAnswerRemove" Runat="server" CommandName="delete" Text="Delete Answer" Font-Size="7"></asp:Button></td>
                                                                                                      </tr>
                                                                                                </itemtemplate>
                                                                                                <FooterTemplate>
                                                                                                      <tr>
                                                                                                            <td valign="top">
                                                                                                                  <asp:Label ID="lblhiAddAnswerQQID" Runat="server" Visible="False" text=""></asp:Label>
                                                                                                            </td>
                                                                                                            <td valign="top">
                                                                                                                  <asp:TextBox ID="txtAnswer" Runat="server"></asp:TextBox></td>
                                                                                                            <td valign="top">
                                                                                                                  <asp:Button id="btnAddAnswer" Runat="server" Text="Add Answer" CommandName="add" Font-Size="7"></asp:Button></td>
                                                                                                      </tr>
                                                                                                </FooterTemplate>
                                                                                          </asp:repeater>
                                                                                    </itemtemplate>
                                                                                    <FooterTemplate>
                                                                                          <tr bgcolor="#99cc66">
                                                                                                <td width="50%"><strong>Add Question:</strong></td>
                                                                                                <td width="25%"><strong></strong></td>
                                                                                                <td width="25%"></td>
                                                                                          </tr>
                                                                                          <tr bgcolor="#99cc66">
                                                                                                <td width="50%"><asp:TextBox ID="txtQuestion" TextMode="MultiLine" Width="90%" Runat="server"></asp:TextBox></td>
                                                                                                <td width="25%"><asp:DropDownList ID="ddlQuestionType" Width="90%" Runat="server">
                                                                                                            <asp:ListItem Value="1">Multiple Choice</asp:ListItem>
                                                                                                            <asp:ListItem Value="3">Text</asp:ListItem>
                                                                                                      </asp:DropDownList></td>
                                                                                                <td width="25%"><asp:Button id="btnAddQuestion" Runat="server" Text="Add Question" CommandName="add" Font-Size="7"></asp:Button></td>
                                                                                          </tr>
                                                      </TABLE>
                                                      </FooterTemplate> </asp:repeater>
Avatar of svy
svy

((Label)childRepeater.Parent.FindControl("lblHidQQID")).Text;

Avatar of sesurb

ASKER

You can't grab it that way. At the minimum you would need to use the e.Item.Parent.FindControl("lblHidQQID").Text but this still does not gt any data.
Avatar of sesurb

ASKER

I think I have maybe fixed this problem. Instead of doing it in the itemcommand if i do it in the item_databound I can get access to the data. Thanks for the attempt.
ASKER CERTIFIED SOLUTION
Avatar of kodiakbear
kodiakbear

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial