I have a nested asp repeater which is displaying all my items correctly. I have another div within the ItemTemplate of each repeater which submits content to my code behind.
<asp:Repeater runat="server" id="repeaterNote" OnItemDataBound="repeaterNote_ItemDataBound">
<ItemTemplate>
<div id="note" class="staff"><p><%# Eval("Content") %></p><ul>
<li><%# Eval("AddedDate") %></li><li>20:29</li>
<li><%# Eval("AddedByName") %></li><li>
<a href="#" onclick="showAddComment(addComment<%# Eval("NoteID") %>)" class="but">Add comment</a></li></ul>
<div id="addComment<%# Eval("NoteID") %>" class="staff" style="display:none">
<asp:TextBox ID="notecommenttext" runat="server" rows="4"> </asp:TextBox>
<asp:Button ID="Button" runat="server" Text="Add" CommandArgument='<%# Eval("NoteID") %>' OnCommand="Add_Comment" />
</div>
</div>
When I submit the button I want to retrieve the content within the textbook "notecommenttext". There doesn't seem to be an easy way to do this. I have tried to set the ID of the textbook to the unique "NoteID" but it appears that cannot be done.
string uniqueNoteID = e.CommandArgument.ToString();
int parent = int.Parse(uniqueNoteID);
TextBox txtName = new TextBox();
foreach(RepeaterItem noteItem in repeaterNote.Items)
{
if (noteItem.ItemType == ListItemType.Item || noteItem.ItemType == ListItemType.AlternatingItem)
{
Notes rin = (Notes)noteItem.DataItem;
if (rin.RelativeNoteId == parent)
{
txtName = (TextBox)noteItem.FindControl("notecommenttext");
}
}
}
The snippet above is from the button callback "Add_Comment", repeaterNote is my top level Repeater id. It seems to have the correct number of RepeaterItems but the DataItem property is always null. I have added an inner foreach loop to iterate over my nested repeater. Again, this correctly identifies only one of the top level repeaters has a nested repeater element, but the DataItem is still null.
Any suggestions on how I can access the content from within the textbook of each repeater?
page_load
, or only if it is not a postback? You would have to set the data and call DataBind everytime for the data to be available from that property. – ps2goat