So basically this is what I have. In the database, there is a table called LocalTalent. Inside this table there are Two Fields, one is the LTName, and the other is the LTID. Now when my client adds a new talent category, I want this to automatically affect the page it is supposed to. Now on this page, talent.aspx, I have a datalist that holds the repeaters. The datalist is trully unneeded. It is not bound in any way, just there incase I do need it bound. Easily removed, or kept, whatever... well, however, I have it there for repeated columns only. Anyway, each category in the table LocalTalent needs to produce it's own repeater to show the newest 20 records added. So if there are 5 categories, I need 5 repeaters displayed with the records it needs as well. I will post my code shortly, but I need help on this ASAP.
Dim strSQL As String
Dim i As Integer = 0
cmdSelect = New OdbcCommand( "SELECT * FROM Talent", conPubs )
Dim dtrAdapter As OdbcDataAdapter
Dim ds As New DataSet()
Dim rep As Repeater
conPubs.Open()
Dim dtrReader As OdbcDataReader = cmdSelect.ExecuteReader()
if dtrReader.HasRows then
while dtrReader.Read()
strSQL = "SELECT a.UserID, a.UserName, b.* FROM Users a, Talent b WHERE a.Talent='" & dtrReader("LTName") & "' AND b.LTID=" & dtrReader("LTID") & " LIMIT 10"
dtrAdapter = New OdbcDataAdapter( strSQL, conPubs)
dtrAdapter.Fill(ds, (dtrReader("LTID")).ToString())
rep = New Repeater
rep.ID = (dtrReader("LTID")).ToString()
rep.HeaderTemplate = New NewRepeater(ListItemType.Header)
rep.ItemTemplate = New NewRepeater(ListItemType.Item)
rep.FooterTemplate = New NewRepeater(ListItemType.Footer)
rep.DataSource = ds.Tables((dtrReader("LTID")).ToString())
rep.DataBind()
end while
end if
dtrReader.Close()
conPubs.Close()
This is what I have and it comes up with this error:
Unable to cast object of type 'NewRepeater' to type 'System.Web.UI.ITemplate'
that is the front end code. The back end is as follows: (done on inline coding)
Public Class NewRepeater
Dim templateType As ListItemType
Sub New(ByVal type As ListItemType)
templateType = type
End Sub
Public Sub InstantiateIn(ByVal container As Control)
Dim ph As New PlaceHolder()
Dim item1 As New Literal()'LTID in header
Dim item2 As New Literal()'LTName in header
Dim item3 As New Literal()'LTName in header
Dim item4 As New Literal()'UserID in item
Dim item5 As New Literal()'UserName in item
Dim item6 As New Literal()'UserName in item
Dim item7 As New Literal()'LTID in Footer
Dim item8 As New Literal()'LTName in Footer
Dim item9 As New Literal()'LTName in Footer
item1.ID = "item1"
item2.ID = "item2"
item3.ID = "item3"
item4.ID = "item4"
item5.ID = "item5"
item6.ID = "item6"
item7.ID = "item7"
item8.ID = "item8"
item9.ID = "item9"
Select Case (templateType)
Case ListItemType.Header
ph.Controls.Add(New LiteralControl("<table border=""0"" cellpadding=""0"" cellspacing=""0"" width=""122""><tr><td><div style=""margin:3px 0px 3px 0px;""><a href=""/Vegas2/Talent/talent.aspx?cat="))
ph.Controls.Add(item1)
ph.Controls.Add(New LiteralControl(""" title="""))
ph.Controls.Add(item2)
ph.Controls.Add(New LiteralControl(" Local Talent""><strong>"))
ph.Controls.Add(item3)
ph.Controls.Add(New LiteralControl("</strong></a></div></td></tr><tr><td>"))
Case ListItemType.Item
ph.Controls.Add(New LiteralControl("<div style=""margin:3px 0px 3px 0px;"">- <a href=""/Vegas2/Profile/?id="))
ph.Controls.Add(item4)
ph.Controls.Add(New LiteralControl(""" title="""))
ph.Controls.Add(item5)
ph.Controls.Add(New LiteralControl("'s Profile"">"))
ph.Controls.Add(item6)
ph.Controls.Add(New LiteralControl("</a></div>"))
AddHandler ph.DataBinding, New EventHandler(AddressOf Item_DataBinding)
Case ListItemType.Footer
ph.Controls.Add(New LiteralControl("</td></tr><tr><td><div style=""margin:12px 0px 0px 2px;""><a href=""/Vegas2/Talent/talent.aspx?cat="))
ph.Controls.Add(item7)
ph.Controls.Add(New LiteralControl(""" title=""View All "))
ph.Controls.Add(item8)
ph.Controls.Add(New LiteralControl(" Listings"">View All """))
ph.Controls.Add(item9)
ph.Controls.Add(New LiteralControl("""</a><br /><a href=""/Vegas2/Register/register.aspx"" title=""Register and Setup Your Profile!"">Become Part of The Local Talent!</a></td></tr></table>"))
AddHandler ph.DataBinding, New EventHandler(AddressOf Item_DataBinding)
End Select
container.Controls.Add(ph)
End Sub
End Class
Shared Sub Item_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs)
Dim ph As PlaceHolder = CType(sender, PlaceHolder)
Dim ri As RepeaterItem = CType(ph.NamingContainer, RepeaterItem)
Dim item1Value As Integer = Convert.ToInt64(DataBinder.Eval(ri.DataItem, "LTID"))
Dim item2Value As String = Convert.ToString(DataBinder.Eval(ri.DataItem, "LTName"))
Dim item3Value As String = Convert.ToString(DataBinder.Eval(ri.DataItem, "LTName"))
Dim item4Value As Integer = Convert.ToInt64(DataBinder.Eval(ri.DataItem, "UserID"))
Dim item5Value As String = Convert.ToString(DataBinder.Eval(ri.DataItem, "UserName"))
Dim item6Value As String = Convert.ToString(DataBinder.Eval(ri.DataItem, "UserName"))
Dim item7Value As Integer = Convert.ToInt64(DataBinder.Eval(ri.DataItem, "LTID"))
Dim item8Value As String = Convert.ToString(DataBinder.Eval(ri.DataItem, "LTName"))
Dim item9Value As String = Convert.ToString(DataBinder.Eval(ri.DataItem, "LTName"))
CType(ph.FindControl("item1"), Literal).Text = item1Value.ToString()
CType(ph.FindControl("item2"), Literal).Text = item2Value.ToString()
CType(ph.FindControl("item3"), Literal).Text = item3Value.ToString()
CType(ph.FindControl("item4"), Literal).Text = item4Value.ToString()
CType(ph.FindControl("item5"), Literal).Text = item5Value.ToString()
CType(ph.FindControl("item6"), Literal).Text = item6Value.ToString()
CType(ph.FindControl("item7"), Literal).Text = item7Value.ToString()
CType(ph.FindControl("item8"), Literal).Text = item8Value.ToString()
CType(ph.FindControl("item9"), Literal).Text = item9Value.ToString()
End Sub
Now I have been screwing around with this all day and cannot seem to be successful. Please help as this is the last stage in a big site. Thank you.
THis is now what I have and it seems as if the sub repeater is either not pulling any rows or is never trully databinding. Only throws the portion of the main repeater.
sub page_load
Dim cmdSelect1 As New OdbcDataAdapter( "SELECT * FROM Talent", conPubs )
Dim ds As Dataset = New DataSet()
Dim cmdSelect2 = New OdbcDataAdapter( "SELECT a.UserID, a.UserName, a.Talent, b.* FROM Users a, Talent b WHERE a.Talent=b.LTID", conPubs )
cmdSelect1.Fill(ds, "main")
cmdSelect2.Fill(ds, "sub")
ds.Relations.Add("myrelation", ds.Tables("main").Columns("LTID"), ds.Tables("sub").Columns("Talent"))
dlMainRepeater.DataSource = ds
dlMainRepeater.DataBind()
end sub
'obviously some stuff was left out that is
'not needed for this question.
Sub dlMainRepeater_ItemDataBound(ByVal sender As Object, ByVal e As DataListItemEventArgs)
Dim dv As DataRowView = CType(e.Item.DataItem, DataRowView)
If Not dv Is Nothing Then
Dim nestedRepeater As Repeater = CType(e.Item.FindControl("rpSubRepeater1"), Repeater)
If Not nestedRepeater Is Nothing Then
nestedRepeater.DataSource = dv.CreateChildView("myrelation")
nestedRepeater.DataBind()
End If
End If
End Sub
''Repeaters are here:
<asp:DataList ID="dlMainRepeater" width="525" ItemStyle-Width="125" s RepeatColumns="4" runat="server">
<ItemTemplate>asdf
<asp:Repeater ID="rpSubRepeater1" runat="server">
<HeaderTemplate>
<table border="0" cellpadding="0" cellspacing="0" width="122"><tr><td><div style="margin:3px 0px 3px 0px;"><a href="/Vegas2/Talent/talent.aspx?cat=<%# DataBinder.Eval(Container.DataItem, "LTID") %>" title="<%# DataBinder.Eval(Container.DataItem, "LTName") %> Local Talent"><strong><%# DataBinder.Eval(Container.DataItem, "LTName") %></strong></a></div></td></tr><tr><td>
</HeaderTemplate>
<ItemTemplate>
adsfasdf
<div style="margin:3px 0px 3px 0px;">- <a href="/Vegas2/Profile/?id=<%# DataBinder.Eval(Container.DataItem, "UserID") %>" title="<%# DataBinder.Eval(Container.DataItem, "UserName") %>'s Profile">"</a></div>
</ItemTemplate>
<FooterTemplate>
</td></tr><tr><td><div style="margin:12px 0px 0px 2px;"><a href="/Vegas2/Talent/talent.aspx?cat=<%# DataBinder.Eval(Container.DataItem, "LTID") %>" title="View All <%# DataBinder.Eval(Container.DataItem, "LTName") %> Listings">View All "<%# DataBinder.Eval(Container.DataItem, "LTName") %>"</a><br /><a href=""/Vegas2/Register/register.aspx"" title=""Register and Setup Your Profile!"">Become Part of The Local Talent!</a></td></tr></table>
</FooterTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:DataList>
solved it myself. thanks :)
hii,
can u send the code,how u solved it would be helpfull to others.
Sure. What I did wrong was forgetting to bind the main repeater as I should have. This is mostly due to changing the code so much that I accidentally left it out.
<script language="vb" runat="server">
Sub Page_Load
if Not Page.IsPostBack then
Dim conPubs As New OdbcConnection( System.Configuration.ConfigurationManager.AppSettings.Get("ConnectionString") )
if Not Cache("TalentMain") Is Nothing and Not Cache("TalentSub") Is Nothing then
Dim ds As DataSet = New DataSet()
ds = Cache("Talent")
ds.Relations.Add("relation", ds.Tables("main").Columns("LTID"), ds.Tables("sub").Columns("LTID"))
dlMainRepeater.DataSource = ds.Tables("main").DefaultView
dlMainRepeater.DataBind()
else
Dim dataAdapt As New OdbcDataAdapter( "SELECT * FROM Talent", conPubs )
Dim ds As DataSet = New DataSet()
dataAdapt.Fill(ds, "main")
dataAdapt = New OdbcDataAdapter( "SELECT UserID, UserName, LTID FROM Users", conPubs )
dataAdapt.Fill(ds, "sub")
Cache.Insert("Talent", ds, Nothing, DateTime.Now.AddMinutes(10), Cache.NoSlidingExpiration)
ds.Relations.Add("relation", ds.Tables("main").Columns("LTID"), ds.Tables("sub").Columns("LTID"))
dlMainRepeater.DataSource = ds.Tables("main").DefaultView
dlMainRepeater.DataBind()
end if
If conPubs.State = ConnectionState.Open then conPubs.Close()
end if
End Sub
Sub dlMainRepeater_OnItemDataBound(ByVal sender As Object, ByVal e As DataListItemEventArgs)
Dim datav As DataRowView = CType(e.Item.DataItem, DataRowView)
If Not datav Is Nothing Then
Dim SubRepeater As Repeater = CType(e.Item.FindControl("SubRepeater"), Repeater)
If Not SubRepeater Is Nothing Then
SubRepeater.DataSource = dv.CreateChildView("relation")
SubRepeater.DataBind()
End If
End If
End Sub
</script>
<asp:DataList ID="dlMainRepeater" width="500" RepeatDirection="Horizontal" ItemStyle-Width="125" OnItemDataBound="dlMainRepeater_OnItemDataBound" RepeatColumns="4" runat="server">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "LTName") %>
<asp:Repeater ID="SubRepeater1" runat="server">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "UserName") %>
</ItemTemplate>
</asp:Repeater>
<%# DataBinder.Eval(Container.DataItem, "LTID") %>
</ItemTemplate>
</asp:DataList>
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.