在另一个中继器内的中继器内查找文本框
我已经列了一份菜单清单。它由两个转发器组成,一个包含产品类型,另一个包含该产品类型的内容。 可以在文本框中输入您想要的内容的数量,我现在想要找到该文本框及其内容。
这就是我的 ASP.NET 代码的样子:
<asp:Repeater ID="ParentRepeater" runat="server" OnItemDataBound="ParentRepeater_ItemDataBound">
<ItemTemplate>
<h2>
<%#DataBinder.Eval(Container.DataItem, "typenavn") %></h2>
<asp:HiddenField ID="HiddenField1" Value='<%# Eval("id") %>' runat="server" />
<asp:Repeater ID="ChildRepeater" runat="server">
<ItemTemplate>
<table>
<tr>
<td style="width: 400px">
<%#DataBinder.Eval(Container.DataItem, "productName") %>
</td>
<td style="width: 400px">
<%#DataBinder.Eval(Container.DataItem, "pris") %>
</td>
<td>
<asp:HiddenField ID="HiddenField2" runat="server" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
这是我到目前为止尝试做的事情:
Repeater ChildRepeater;
foreach (RepeaterItem item1 in ParentRepeater.Items)
{
if (item1.ItemType == ListItemType.Item || item1.ItemType == ListItemType.AlternatingItem)
{
ChildRepeater = (Repeater)item1.FindControl("ChildRepeater");
foreach (RepeaterItem item2 in ChildRepeater.Items)
{
if (item2.ItemType == ListItemType.Item || item2.ItemType == ListItemType.AlternatingItem)
{
TextBox txt = (TextBox)item2.FindControl(("MainContent_ParentRepeater_ChildRepeater_0_HB1_0")) as TextBox; // MainContent_ParentRepeater_ChildRepeater_0_HB
}
}
}
break;
}
首先进入父中继器,然后进入它的子中继器。 但它找不到我的文本框。
任何机构有和想法吗?
I have made a menu list. It consists of two repeater, one with the productType and the other with the content of that product type.
It is possible to enter how many of the content you want in a text box and I now want to find the textbox and its content.
This is how my ASP.NET code looks like:
<asp:Repeater ID="ParentRepeater" runat="server" OnItemDataBound="ParentRepeater_ItemDataBound">
<ItemTemplate>
<h2>
<%#DataBinder.Eval(Container.DataItem, "typenavn") %></h2>
<asp:HiddenField ID="HiddenField1" Value='<%# Eval("id") %>' runat="server" />
<asp:Repeater ID="ChildRepeater" runat="server">
<ItemTemplate>
<table>
<tr>
<td style="width: 400px">
<%#DataBinder.Eval(Container.DataItem, "productName") %>
</td>
<td style="width: 400px">
<%#DataBinder.Eval(Container.DataItem, "pris") %>
</td>
<td>
<asp:HiddenField ID="HiddenField2" runat="server" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
This is what I have tried to do so far:
Repeater ChildRepeater;
foreach (RepeaterItem item1 in ParentRepeater.Items)
{
if (item1.ItemType == ListItemType.Item || item1.ItemType == ListItemType.AlternatingItem)
{
ChildRepeater = (Repeater)item1.FindControl("ChildRepeater");
foreach (RepeaterItem item2 in ChildRepeater.Items)
{
if (item2.ItemType == ListItemType.Item || item2.ItemType == ListItemType.AlternatingItem)
{
TextBox txt = (TextBox)item2.FindControl(("MainContent_ParentRepeater_ChildRepeater_0_HB1_0")) as TextBox; // MainContent_ParentRepeater_ChildRepeater_0_HB
}
}
}
break;
}
First going into the parentrepeater and the going into it's chilrepeaters.
But it cant find my textbox.
Any body have and idea??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
或者
您必须在 RepeaterItem 中搜索 TextBox。因此,您要么处理内部 Repeater 的 ItemDataBound 事件,要么简单地迭代所有 RepeaterItem:
or
You have to search for the TextBox in the RepeaterItem. So you either handle the inner Repeater's ItemDataBound event or you simply iterate all RepeaterItems:
尝试此类中的两种方法之一:(将此类放入 App_Code)
您将使用 FindControlRecursive() 来查找特定的 TextBox,并使用 ModifyControl 对所有 TextBox 进行修改/执行某些操作。
Try one of the two methods in this class: (Put this class in App_Code)
You'd use FindControlRecursive() to find a specific TextBox and you'd use ModifyControl to modify/do something with all the TextBox's.