By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 920 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

Repeater DataItemBound not firing

P: n/a
I am trying use a repeater to process through the results of a sql query and produce a table that may or may not have multiple rows per record in the query, depending upon whether the technicians have added notes to their work. I can not get the OnItemDataBound event to fire for the repeater control. I have created a scaled-down version of what it is that I am trying to accomplish just to make it easier to read. This does not work either. The code was based on MSKB article 317429. The trimmed down code should do nothing more that list the first data item in each record down the page

Just to eliminate potential problems, I did write the sql command out to the screen as well. I then cut and paste the code into the Query Analyzer to make sure that it was not an issue with the query itself

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="TestRepeater.aspx.vb" Inherits="MM2003.TestRepeater"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><title>TestRepeater</title><meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1"><meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1"><meta name="vs_defaultClientScript" content="JavaScript"><meta name="vs_targetSchema" content=""></HEAD><body><form id="Form1" method="post" runat="server"><P><asp:Label id="lblMessage" runat="server"></asp:Label></P><asp:Repeater id="rptWOTime" runat="server" OnItemDataBound="rptWOTime_ItemDataBound"><ItemTem plate><asp:Literal ID="litWOTime" Runat=server></asp:Literal></ItemTemplate></asp:Repeater></form></body></HTML

Imports System.Dat
Imports System.Data.Commo
Imports System.Data.SqlClien

Public Class TestRepeate
Inherits System.Web.UI.Pag

#Region " Web Form Designer Generated Code

'This call is required by the Web Form Designer
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent(

End Su
Protected WithEvents rptWOTime As System.Web.UI.WebControls.Repeate
Protected WithEvents lblMessage As System.Web.UI.WebControls.Labe

'NOTE: The following placeholder declaration is required by the Web Form Designer
'Do not delete or move it
Private designerPlaceholderDeclaration As System.Objec

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Ini
'CODEGEN: This method call is required by the Web Form Designe
'Do not modify it using the code editor
End Su

#End Regio

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Loa
Dim conMM As SqlConnectio
Dim cmdMM As SqlComman
Dim dtrMM As SqlDataReade
Dim strWork As Strin
Dim strWONum As String = "6958
Dim strAccountID As String = "SAMP

conMM = New SqlConnection(Session("MMWAConnStr")

strWork = "select convert(char,DateOfService,101) as DateOfService, " &
"TimeIn, HoursWorked, " &
"isnull(LastName,'') as LastName, isnull(FirstName,'') as FirstName, " &
"isnull(WorkPerformedName,'') as WorkPerformedName, " &
"isnull(LaborNotes,'') as LaborNotes " &
"from " & Session("MMWADBName") & "..tblWOHours hours " &
"left outer join " & Session("MMWADBName") & "..tblTechnicians techs " &
"on techs.TechID = hours.TechID " &
"left outer join " & Session("MMWADBName") & "..tblCBO_WorkPerformed wp " &
"on wp.WorkPerformedID = hours.WorkPerformedID " &
"where WONum = " & strWONum & " and " &
"PatriotAccountID = '" & strAccountID & "' " &
"order by DateOfService, TimeIn

cmdMM = New SqlCommand(strWork, conMM
dtrMM = cmdMM.ExecuteReader(

lblMessage.Text = strWor

If Not dtrMM.Read The
lblMessage.Text &= "<br><br>No records found"
lblMessage.Text &= "<br><br>Records were found"
rptWOTime.DataSource = dtrMM
End If
End Sub

Sub rptWOTime_ItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs)
If e.Item.ItemType = ListItemType.Item Or _
e.Item.ItemType = ListItemType.AlternatingItem Then
Dim dbr As DbDataRecord = CType(e.Item.DataItem, DbDataRecord)
Dim litWOTime As Literal = e.Item.FindControl("litWOTime")
litWOTime.Text = dbr("DateOfService") & "<BR>"
End If
End Sub

End Class

Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
Chances are the event handler (rptWOTime_ItemDataBound) is not wired up
to the Repeater's ItemDataBound event. One way to do this is to add
OnItemDataBound="rptWOTime_ItemDataBound" in the declarative syntax of
the Repeater control:

<asp:Repeater OnItemDataBound="rptWOTime_ItemDataBound"

Another option is to add the Handles keyword to the event handler

Sub rptWOTime_ItemDataBound(ByVal sender As Object, ByVal e As
RepeaterItemEventArgs) Handles rptWOTime.ItemDataBound
End Sub

If you are using VS.NET, you can automatically get the Handles keyword
added by selecting the repWOTime item in the DropDownList at the top of
the code-behind class, and then in the other DropDownList, picking the
ItemDataBound event.


Scott Mitchell

* When you think ASP, think!
Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.