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
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