Handles clause requires a WithEvents variable defined in the cont
HejJeg får følgende fejl på min side:
Handles clause requires a WithEvents variable defined in the containing type or one of its base types.
i denne linie: Handles Repeater2.ItemDataBound
Min kode ser således ud:
------------------------------------------------------------------
.aspx fil:
------------------------------------------------------------------
<table style="width: 100%" cellspacing="0" class="ForumTable">
<tr>
<td style="width: 66%" class="TableHeader">
Forum</td>
<td style="width: 7%" class="TableHeader">
Emner</td>
<td style="width: 7%" class="TableHeader">
Indlæg</td>
<td style="width: 20%" class="TableHeader">
Sidste indlæg</td>
</tr>
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
<tr>
<td style="width: 66%" class="Header">
<%#Eval("Title")%><asp:Label ID="IDLabel" runat="server" Text='<%#Eval("ID")%>' Visible="false"></asp:Label></td>
<td style="width: 7%" class="Header">
</td>
<td style="width: 7%" class="Header">
</td>
<td style="width: 20%" class="Header">
</td>
</tr>
<asp:Repeater ID="Repeater2" runat="server" OnItemDataBound="Repeater2_ItemDataBound">
<ItemTemplate>
<tr>
<td style="width: 66%; padding-left: 10px; padding-bottom: 5px; padding-top: 5px;">
<strong>
<a href="Threads.aspx?ForumID=<%#Eval("ID")%>"><%#Eval("Title")%></a></strong><br />
<span style="font-size: 7pt;"><%#Eval("Description")%></span></td>
<td style="width: 7%; text-align: center; vertical-align:middle; padding-bottom: 5px; padding-top: 5px;">
<asp:Label ID="SubjectCount" runat="server" Text='<%#Eval("ID")%>'></asp:Label></td>
<td style="width: 7%; text-align: center; vertical-align:middle; padding-bottom: 5px; padding-top: 5px;">
<asp:Label ID="TotalCount" runat="server" Text="Label"></asp:Label></td>
<td style="width: 20%; padding-bottom: 5px; padding-top: 5px;">
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
</table>
------------------------------------------------------------------
.cs fil:
------------------------------------------------------------------
Protected Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs) _
Handles Repeater1.ItemDataBound
Dim myRepeater As Repeater = CType(e.Item.FindControl("Repeater2"), Repeater)
Dim myID As Label = CType(e.Item.FindControl("IDLabel"), Label)
Dim CatID As Integer = myID.Text
Dim Connstr As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
Dim Connection As New SqlConnection(Connstr)
Dim command As New SqlCommand("SELECT ID, Title, Description from Forums WHERE CategoryID = '" & CatID & "'", Connection)
Connection.Open()
myRepeater.DataSource = command.ExecuteReader(CommandBehavior.CloseConnection)
myRepeater.DataBind()
End Sub
Protected Sub Repeater2_ItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs) _
Handles Repeater2.ItemDataBound
Dim myID As Label = CType(e.Item.FindControl("SubjectCount"), Label)
Dim CatID As Integer = myID.Text
Dim Connstr As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
Dim Connection As New SqlConnection(Connstr)
Dim command As New SqlCommand("SELECT Count(*) AS SubjectCount from Forums WHERE Topic = '1' AND ForumID = '" & CatID & "'", Connection)
Connection.Open()
Dim Reader As System.Data.SqlClient.SqlDataReader
Reader = command.ExecuteReader(CommandBehavior.CloseConnection)
myID.Text = Reader("SubjectCount").ToString
End Sub
Tror det har noget at gøre med eat repeater2 ligger inden i den anden repeater..