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

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

P: n/a


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

Feb 26 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Show us your SQL statement

--
David Wier
MVP/ASPInsider
http://aspnet101.com
http://aspexpress.com
"shapper" <md*****@gmail.comwrote in message
news:11*********************@z35g2000cwz.googlegro ups.com...
>

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

Feb 26 '07 #2

P: n/a
There is no "SQL Statement" for him to show you. Go back and look at his code.
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"David Wier" wrote:
Show us your SQL statement

--
David Wier
MVP/ASPInsider
http://aspnet101.com
http://aspexpress.com
"shapper" <md*****@gmail.comwrote in message
news:11*********************@z35g2000cwz.googlegro ups.com...


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


Feb 26 '07 #3

P: n/a
On Feb 26, 8:10 pm, Peter Bromberg [C# MVP]
<pbromb...@yahoo.yabbadabbadoo.comwrote:
There is no "SQL Statement" for him to show you. Go back and look at his code.
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net

"David Wier" wrote:
Show us your SQL statement
--
David Wier
MVP/ASPInsider
http://aspnet101.com
http://aspexpress.com
"shapper" <mdmo...@gmail.comwrote in message
news:11*********************@z35g2000cwz.googlegro ups.com...
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
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

Feb 27 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.