Repeater. I see only the last record. Have no idea why!


S

shapper

Hello,

I am created an Asp.Net 2.0 repeater implementing the ITemplate class.

I know my datasource, a datatable has 6 rows, but the repeater only
displays the last one.

If I add more rows to my datatable I keep seeing only the last record
on my repeater. any idea why?

This is my ITemplate code:

1
2 Private Class rFeedbackTemplate
3 Implements ITemplate
4
5 Private Type As ListItemType
6 Protected WithEvents lMessage As New Label
7
8 Public Sub New(ByVal type As ListItemType)
9 Me.Type = type
10 End Sub ' New
11
12 ' InstantiateIn
13 Public Sub InstantiateIn(ByVal container As Control)
Implements ITemplate.InstantiateIn
14 Select Case Me.Type
15 Case ListItemType.Header ' Header
template
16 Case ListItemType.Item ' Item
template
17 container.Controls.Add(lMessage)
18 Case ListItemType.AlternatingItem ' Alternating
item template
19 Case ListItemType.Footer ' Footer
template
20 End Select
21 End Sub ' InstantiateIn
22
23 Private Sub lMessage_DataBinding(ByVal sender As Object,
ByVal e As System.EventArgs) Handles lMessage.DataBinding
24 Dim container As RepeaterItem =
CType(lMessage.NamingContainer, RepeaterItem)
25 lMessage.Text = DataBinder.Eval(container.DataItem,
"Message")
26 End Sub ' lMessage_DataBinding
27
28 Private Sub lMessage_Init(ByVal sender As Object, ByVal e
As EventArgs) Handles lMessage.Init
29 With lMessage
30 .CssClass = "lMessage"
31 .ID = "lMessage"
32 End With
33 End Sub ' lMessage_Init
34
35 End Class ' rFeedbackTemplate

My repeater events:

1
2 Private Sub rFeedback_Init(ByVal sender As Object, ByVal e As
System.EventArgs) Handles rFeedback.Init
3 rFeedback.ID = "rFeedback"
4 rFeedback.ItemTemplate = New
rFeedbackTemplate(ListItemType.Item)
5 End Sub ' rFeedback_Init
6
7 Private Sub rFeedback_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles rFeedback.Load
8 If Not Page.IsPostBack Then
9 With rFeedback
10 .DataSource = rFeedback_DataSource()
11 .DataBind()
12 End With
13 End If
14 End Sub ' rFeedback_Load
15
16 ' rFeedback_DataSource
17 Private Function rFeedback_DataSource() As DataTable
18 Dim dtFeedback As New DataTable
19 dtFeedback.Columns.Add(New DataColumn("Message",
GetType(String)))
20 For Each message As String In Me.Messages
21 Dim drFeedback As DataRow = dtFeedback.NewRow
22 drFeedback("Message") = message
23 dtFeedback.Rows.Add(drFeedback)
24 Next message
25 Return dtFeedback
26 End Function ' rFeedback_DataSource

Any idea why I only see the last record of my data source in my
repeater?

Thanks,

Miguel
 
Ad

Advertisements

Ad

Advertisements

S

shapper

There is no "SQL Statement" for him to show you. Go back and look at his code.

Hi,

I don't have an SQL statement.

This code is inside an user control.

The user control as a property as follows:

' Messages
Private _Messages As New Generic.List(Of String)
Public Property Messages() As Generic.List(Of String)
Get
Return _Messages
End Get
Set(ByVal value As Generic.List(Of String))
_Messages = value
End Set
End Property ' Messages

On my page I have something like:
With MyUserControl.Messages
.Add("Message01")
.Add("Message02")
...
.Add("Message06")
End With

On my UserControl, inside rFeedback_DataSource, I place the following
code:
Response.Write(dtFeedback.Rows.Count.ToString)

I get 6!

I looked everywhere, all day, to try to figure out what is going on
but I have no idea.

Could someone, please help me out?

Thanks,
Miguel
 

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

Top