为什么我无法在转发器中访问此文本框我在rgroups itemdatabind上使用了以下内容 无论我做什么,都说无法引用该对象。请在vb.net中提供任何答案
<asp:Repeater ID="rGroups" Runat="server">
<HeaderTemplate>
<ul id="prod_nav" class="clearfix">
<asp:TextBox ID="txt" Text="<%#DataBinder.Eval(Container.DataItem,"groupid")%>" runat="server">
</asp:TextBox>
</HeaderTemplate>
<ItemTemplate>
<li class="top"><a href="05-Pink-02-Category-List.html" class="top_link">
<span class="down"> <%#D ataBinder.Eval(Container.DataItem,"groupname")%></span></a>
<asp:Repeater ID="rSubgroups" Runat="server">
<HeaderTemplate>
<ul class="sub">
<li class="clearfix">
<ul>
</HeaderTemplate> <ItemTemplate>
<li><a href="default.aspx?subgrp=<%#DataBinder.Eval(Container.DataItem,"subgroupId")%>"><%#DataBinder.Eval(Container.DataItem,"subgroupname")%></a></li>
</ItemTemplate>
<FooterTemplate> </ul> </li> </ul> </FooterTemplate>
答案 0 :(得分:1)
protected void rGroups_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Header) // For Header
{
TextBox txt = e.Item.FindControl("txt") as TextBox;
}
}
VB.Net:
Protected Sub rGroups_ItemDataBound(sender As Object, e As RepeaterItemEventArgs) Handles rGroups.ItemDataBound
If e.Item.ItemType = ListItemType.Header Then
' For Header '
Dim txt As TextBox = TryCast(e.Item.FindControl("txt"), TextBox)
End If
End Sub
答案 1 :(得分:1)
是的,你可以访问这个文本框,但它不是一个漂亮的代码:
你必须在需要的repeateritem.cotrols上调用FindControl函数