Repeater DataSource. This is driving me crazy.

S

shapper

Hello,

I created a Repeater at runtime with an AccessDataSource.Everything
Works fine!

Now I need to use the same repeater but with a DataSource created in my
VB.Net code.

I created a DataView but the Repeater doesn't show anything!
I don't get any error so I have no idea what is going on.

This is my function which creates the datasource which in this moment
has only one record:

Function DataSource() As ICollection

' Define channels data table
Dim dt As DataTable

' Create channels data table
dt = New DataTable
dt.Columns.Add(New DataColumn("ChannelId", GetType(String)))
dt.Columns.Add(New DataColumn("ChannelName", GetType(String)))

' Add news channel data row
Dim dr As DataRow
dr = dt.NewRow
dr(0) = "News"
dr(1) = "Noticias"
dt.Rows.Add(dr)

' Return RSS channel dataview
DataSource = New DataView(dt)

End Function

Could someone please help me out?

Thanks,
Miguel
 
K

Ken Cox [Microsoft MVP]

Here's code that seems to work. Perhaps you could compare it against your
own?

Ken
Microsoft MVP [ASP.NET]

<%@ page language="VB" %>

<%@ import namespace="System.Data" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
Function DataSource() As ICollection

' Define channels data table
Dim dt As DataTable

' Create channels data table
dt = New DataTable
dt.Columns.Add(New DataColumn _
("ChannelId", GetType(String)))
dt.Columns.Add(New DataColumn _
("ChannelName", GetType(String)))

' Add news channel data row
Dim dr As DataRow
dr = dt.NewRow
dr(0) = "News"
dr(1) = "Noticias"
dt.Rows.Add(dr)
dr = dt.NewRow
dr(0) = "Sports"
dr(1) = "Sports2"
dt.Rows.Add(dr)

' Return RSS channel dataview
Return New DataView(dt)

End Function

Protected Sub Page_Load _
(ByVal sender As Object, _
ByVal e As System.EventArgs)
If Not IsPostBack Then
Repeater1.DataSource = DataSource()
Repeater1.DataBind()
End If
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>DataSource and Repeater</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:repeater id="Repeater1" runat="server">
<itemtemplate>
<asp:label runat="server" id="lblNews">
<%#Eval("ChannelId")%>:<%#Eval("ChannelName")%></asp:label><br
/>
</itemtemplate>
</asp:repeater>
</div>
</form>
</body>
</html>
 
S

shapper

I just solved it as follows:

' <Asp:Repeater>
Private Sub rRSSChannels_Init(ByVal sender As Object, ByVal e As
EventArgs) Handles rRSSChannels.Init

' Define rRSSChannels properties
With rRSSChannels
.DataSource = rRSSChannels_DataSource()
End With

' Define repeater item template
rRSSChannels.ItemTemplate = New rRSSChannelsTemplate(Me,
ListItemType.Item)

End Sub

Private Sub rRSSChannels_Load(ByVal sender As Object, ByVal e As
EventArgs) Handles rRSSChannels.Load

' Bind repeater to its data source
If Not IsPostBack Then
rRSSChannels.DataBind()
End If

End Sub

Here's code that seems to work. Perhaps you could compare it against your
own?

Ken
Microsoft MVP [ASP.NET]

<%@ page language="VB" %>

<%@ import namespace="System.Data" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
Function DataSource() As ICollection

' Define channels data table
Dim dt As DataTable

' Create channels data table
dt = New DataTable
dt.Columns.Add(New DataColumn _
("ChannelId", GetType(String)))
dt.Columns.Add(New DataColumn _
("ChannelName", GetType(String)))

' Add news channel data row
Dim dr As DataRow
dr = dt.NewRow
dr(0) = "News"
dr(1) = "Noticias"
dt.Rows.Add(dr)
dr = dt.NewRow
dr(0) = "Sports"
dr(1) = "Sports2"
dt.Rows.Add(dr)

' Return RSS channel dataview
Return New DataView(dt)

End Function

Protected Sub Page_Load _
(ByVal sender As Object, _
ByVal e As System.EventArgs)
If Not IsPostBack Then
Repeater1.DataSource = DataSource()
Repeater1.DataBind()
End If
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>DataSource and Repeater</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:repeater id="Repeater1" runat="server">
<itemtemplate>
<asp:label runat="server" id="lblNews">
<%#Eval("ChannelId")%>:<%#Eval("ChannelName")%></asp:label><br
/>
</itemtemplate>
</asp:repeater>
</div>
</form>
</body>
</html>

shapper said:
Hello,

I created a Repeater at runtime with an AccessDataSource.Everything
Works fine!

Now I need to use the same repeater but with a DataSource created in my
VB.Net code.

I created a DataView but the Repeater doesn't show anything!
I don't get any error so I have no idea what is going on.

This is my function which creates the datasource which in this moment
has only one record:

Function DataSource() As ICollection

' Define channels data table
Dim dt As DataTable

' Create channels data table
dt = New DataTable
dt.Columns.Add(New DataColumn("ChannelId", GetType(String)))
dt.Columns.Add(New DataColumn("ChannelName", GetType(String)))

' Add news channel data row
Dim dr As DataRow
dr = dt.NewRow
dr(0) = "News"
dr(1) = "Noticias"
dt.Rows.Add(dr)

' Return RSS channel dataview
DataSource = New DataView(dt)

End Function

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

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top