why cant i find the control txt in this vb.net asp:repeater no matter what i do on rgroups itembound
-
12-11-2019 - |
Question
i cant find the control txt which is a textbox in the repeater i have used the following on rgroups itemdatabound event
------------itemdatabound code
Protected Sub rGroups_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rGroups.ItemDataBound
Dim dv As DataRowView = TryCast(e.Item.DataItem, DataRowView)
If dv IsNot Nothing Then
Dim rptOrderDetails As Repeater = TryCast(e.Item.FindControl("rSubgroups"), Repeater)
Dim control1 As Control = rGroups.Items(0).FindControl("txt")
Dim txtbox As TextBox = DirectCast(control1, TextBox)
If rptOrderDetails IsNot Nothing Then
Dim dv_co As New DataView(dssubmenu)
dv_co.RowFilter = "groupId = '" + txtbox.Text + "'"
rptOrderDetails.DataSource = dv_co
rptOrderDetails.DataBind()
End If
End If
End Sub
------------repeater code
<asp:Repeater ID="rGroups" Runat="server">
<HeaderTemplate>
<ul id="prod_nav" class="clearfix">
</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="txt" Text="<%#DataBinder.Eval(Container.DataItem,"groupid")%>" runat="server"> </asp:TextBox>
<li class="top"><a href="05-Pink-02-Category-List.html" class="top_link"> <span class="down"> <%#DataBinder.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="partviewer.aspx?subgrp=<%#DataBinder.Eval(Container.DataItem,"subgroupId")%>"> <%#DataBinder.Eval(Container.DataItem,"subgroupname")%></a></li>
</ItemTemplate>
<FooterTemplate> </ul> </li> </ul> < </FooterTemplate>
Solution
You will probably want to get the txt
control for the databound item in the Repeater
, not from the Repeater
control itself. The eventargs argument for the ItemDataBound
event contains the newly created RepeaterItem
. It is from that item you want to retrieve your control:
Dim control1 As Control = e.Item.FindControl("txt")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow