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>Questi on</strong ></td>
<td width="25%"><strong>Type</ strong></t d>
<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="eventRepeat er_ItemCom mand" OnItemDataBound="eventRepa ter_ItemDa taBound" EnableViewState=True datasource='<%# Container.DataItem.Row.Get ChildRows( "myrelatio n")%>'>
<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_Que stion")%>' >
</asp:Label>
</td>
<td><%# Container.DataItem("QC_Ans wer") %></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:TextB ox></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></stro ng></td>
<td width="25%"></td>
</tr>
<tr bgcolor="#99cc66">
<td width="50%"><asp:TextBox ID="txtQuestion" TextMode="MultiLine" Width="90%" Runat="server"></asp:TextB ox></td>
<td width="25%"><asp:DropDownL ist ID="ddlQuestionType" Width="90%" Runat="server">
<asp:ListItem Value="1">Multiple Choice</asp:ListItem>
<asp:ListItem Value="3">Text</asp:ListIt em>
</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>
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>Questi
<td width="25%"><strong>Type</
<td width="25%"></td>
</tr>
</HeaderTemplate>
<itemtemplate>
<tr>
<td><%# DataBinder.Eval(Container.
<td><%# DataBinder.Eval(Container.
<td><asp:Button id="btnQuestionRemove" Runat="server" Text="Remove Question" Font-Size="7"></asp:Button
</tr>
<asp:repeater id="childRepeater" runat="server" OnItemCommand="eventRepeat
<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_Que
</asp:Label>
</td>
<td><%# Container.DataItem("QC_Ans
<td>
<asp:Button id="btnAnswerRemove" Runat="server" CommandName="delete" Text="Delete Answer" Font-Size="7"></asp:Button
</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:TextB
<td valign="top">
<asp:Button id="btnAddAnswer" Runat="server" Text="Add Answer" CommandName="add" Font-Size="7"></asp:Button
</tr>
</FooterTemplate>
</asp:repeater>
</itemtemplate>
<FooterTemplate>
<tr bgcolor="#99cc66">
<td width="50%"><strong>Add Question:</strong></td>
<td width="25%"><strong></stro
<td width="25%"></td>
</tr>
<tr bgcolor="#99cc66">
<td width="50%"><asp:TextBox ID="txtQuestion" TextMode="MultiLine" Width="90%" Runat="server"></asp:TextB
<td width="25%"><asp:DropDownL
<asp:ListItem Value="1">Multiple Choice</asp:ListItem>
<asp:ListItem Value="3">Text</asp:ListIt
</asp:DropDownList></td>
<td width="25%"><asp:Button id="btnAddQuestion" Runat="server" Text="Add Question" CommandName="add" Font-Size="7"></asp:Button
</tr>
</TABLE>
</FooterTemplate> </asp:repeater>
((Label)childRepeater.Pare nt.FindCon trol("lblH idQQID")). Text;
ASKER
You can't grab it that way. At the minimum you would need to use the e.Item.Parent.FindControl( "lblHidQQI D").Text but this still does not gt any data.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.