Repeater DataItemBound not firing

G

Guest

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

TestRepeater.asp
--------------------
<%@ 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="http://schemas.microsoft.com/intellisense/ie5"></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"><ItemTemplate><asp:Literal ID="litWOTime" Runat=server></asp:Literal></ItemTemplate></asp:Repeater></form></body></HTML

TestRepeater.aspx.v
------------------------
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
InitializeComponent(
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

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

lblMessage.Text = strWor

If Not dtrMM.Read The
lblMessage.Text &= "<br><br>No records found"
Else
lblMessage.Text &= "<br><br>Records were found"
rptWOTime.DataSource = dtrMM
rptWOTime.DataBind()
End If
dtrMM.Close()
conMM.Close()
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
 
S

Scott Mitchell [MVP]

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"
....>...</asp:Repeater>

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

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.

hth


--

Scott Mitchell
(e-mail address removed)
http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com

* When you think ASP, think 4GuysFromRolla.com!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top