|
-
Feb 13th, 2009, 07:13 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Help replacing Listview with Repeater
Guys,
I have a page that is working great using an accordion control with listviews as items. But I now have to take this back to .net 3.0, so no ListView. Can anybody help me do this please? I havent really used the repeater before...
Some code below. You can see that I am reading from an XML file of sections, each section has questions. My listviews actually hold instances of a custom control for each question, the CustomControl has properties that match the fields required in each question.
So, I need to use the repeater control to host the custom controls and get the data fomr the XML in there. The databind was easy on the listview...
Hope that makes sense...
Bob
Accordion Data bind event...
Code:
Protected Sub accMain_ItemDataBound(ByVal sender As Object, ByVal e As AccordionItemEventArgs)
Dim itemIndex As Integer = e.ItemIndex
Dim itemType As AccordionItemType = e.ItemType
If itemType = AccordionItemType.Content Then
'This gets the questions with any completed data.
Dim document As XDocument = XDocument.Load(Session("str_XMLDataFile"))
Dim sectionName As String = XPathBinder.Eval(DataBinder.GetDataItem(e.AccordionItem), "@SectionName").ToString()
Dim questions = From question In document.Descendants("Question") _
Where question.Parent.Attribute("SectionName").Value = sectionName _
Select Text = question.Element("Text").Value, _
Comment = question.Element("Comment").Value, _
VDSCode = question.Element("VDSCode").Value, _
Category = question.Element("Category").Value, _
YesNo = question.Element("YesNo").Value
Dim lstQuestions As ListView = TryCast(e.AccordionItem.FindControl("lstQuestions"), ListView)
lstQuestions.DataSource = questions
lstQuestions.DataBind()
End If
End Sub
And the HTML for the accordion control, with the listview...
HTML Code:
<cc1:Accordion ID="accMain" runat="server" AutoSize="None" FadeTransitions="true" TransitionDuration="200" FramesPerSecond="40" RequireOpenedPane="false" SuppressHeaderPostbacks="true" DataSourceID="xmlDataSourceSections" onitemdatabound="accMain_ItemDataBound">
<HeaderTemplate>
<asp:Label ID="SectionNameLabel" runat="server" Font-Bold="true" Font-Size="Larger"
Text='<%# (Container.DisplayIndex + 1).ToString() + ". " + XPath("@SectionName")%>' />
</HeaderTemplate>
<ContentTemplate>
<%--The content template for the Accordion Template which is a ListView--%>
<%--field headings--%>
<asp:Label ID="Label6" runat="server" Font-Bold="True" Font-Underline="True" ForeColor="#006600" Width="260px"></asp:Label>
<asp:Label ID="Label2" runat="server" Font-Bold="True" Font-Underline="True" ForeColor="#006600" Text="Yes / No" Width="70px"></asp:Label>
<asp:Label ID="Label3" runat="server" Font-Bold="True" Font-Underline="True" ForeColor="#006600" Text="Category" Width="70px"></asp:Label>
<asp:Label ID="Label4" runat="server" Font-Bold="True" Font-Underline="True" ForeColor="#006600" Text="VDS Code" Width="90px"></asp:Label>
<asp:Label ID="Label5" runat="server" Font-Bold="True" Font-Underline="True" ForeColor="#006600" Text="Comment" Width="800px"></asp:Label>
<br />
<asp:ListView ID="lstQuestions" runat="server">
<ItemTemplate>
<%--call the QuestionControl--%>
<Custom:QuestionControl runat="server" ID="customControl" QCategory='<%#Eval("Category") %>' QVDSCode='<%#Eval("VDSCode") %>' QYesno='<%#Eval("YesNo") %>' QComment='<%#Eval("Comment") %>' QText='<%#Eval("Text") %>' />
<br />
<br />
</ItemTemplate>
<LayoutTemplate>
<div ID="itemPlaceholderContainer" runat="server">
<span ID="itemPlaceholder" runat="server"/>
</div>
</LayoutTemplate>
</asp:ListView>
<%--End of Accordion content Template--%>
</ContentTemplate>
</cc1:Accordion>
"I dislike 7 am. If 7 am were a person, I would punch 7 am in the biscuits." - Paul Ryan, DailyRamblings
-
Feb 14th, 2009, 02:44 PM
#2
Re: Help replacing Listview with Repeater
The listview is an 'advanced' version of the repeater so you still do pretty much what you did with the listview.
Have you tried this code out? Does it work for you? I mean, after replacing the listview with repeaters. You still use the ItemTemplate, but the LayoutTemplate is what sits outside the repeater.
-
Feb 15th, 2009, 05:12 PM
#3
Thread Starter
Fanatic Member
Re: Help replacing Listview with Repeater
Erm... yeah. Find and replace all works a treat. How stupid do I feel.
No more that normal I guess.
Thanks Froggy.
Bob
"I dislike 7 am. If 7 am were a person, I would punch 7 am in the biscuits." - Paul Ryan, DailyRamblings
-
Feb 16th, 2009, 07:54 AM
#4
Re: [RESOLVED] Help replacing Listview with Repeater
No prob, it's alright to hesitate
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|