Displaying information using repeater - asp.net

i am trying to display a list of products
i am using a repeater, the repeater is working perfectly but its not showing the information as i want. i want to display in columns each colums has 6 products and it repeat depending on the number of products.
this is a sample of the code that i am using
page.aspx.cs
AllProducts = pm.GetProductOfMerchantByCat(ID, catid);
ProductRepeater.DataSource = AllProducts;
ProductRepeater.DataBind();
page.aspx
<asp:Repeater id="ProductRepeater" runat="server" Visible="true">
<HeaderTemplate>
<ul id="ProductsContent" class="jcarousel-skin-tango">
</HeaderTemplate>
<ItemTemplate>
<li>
<div class="product">
<h4><%# DataBinder.Eval(Container.DataItem, "Name")%></h4>
<asp:HiddenField ID="HiddenFeildQuantity"
Value='<%# Eval("Quantity") %>'
runat="server" />
</div>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
any help would be great .. thank you

Hey as per my Understanding you need to use DataList Instead of Repater.
Check This property
RepeatColumns
RepeatDirection
MSDN : http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.datalist.aspx

Related

How to include html inside anchor tag in Sitecore

I have a situation where there is HTML inside an anchor tag. And the author should be able to edit both the anchor (href) & other fields.
aspx:
<asp:Repeater ID="rpEvents" runat="server" ItemType="Sitecore.Data.Items.Item">
<HeaderTemplate>
<div class="col-md-3">
</HeaderTemplate>
<ItemTemplate>
<a href="offers/spring.html">
<sc:Image runat="server" Field="offer image" Item=<%#Container.DataItem%> />
<h3><sc:Text runat="server" Field="Offer Title" Item=<%#Container.DataItem%> /></h3>
</a>
</ItemTemplate>
<FooterTemplate>
</div>
</FooterTemplate>
</asp:Repeater>
I would do this by turning the <a> into <asp:Hyperlink> & assigning its NavigateURL property from code behind, but then the author cannot edit it in experience editor.
How is this done in Sitecore.
You can wrap the other HTML elements using the Link field, which will allow all fields to continue to be edited from the Experience Editor:
<ItemTemplate>
<sc:Link Field="Offer Link" Item="<%# Container.DataItem %>" runat="server">
<sc:Image Field="Offer Title" Item="<%# Container.DataItem %>" runat="server" />
<h3><sc:Text Field="offer image" Item="<%# Container.DataItem %>" runat="server" /></h3>
</sc:Link>
</ItemTemplate>
The Link can still be set, the image changed or the separate text field edited:
An option is to use the sc:EditFrame inside a repeater, that looks like:
<asp:Repeater runat="server" ID="AccordionRowRepeater">
<ItemTemplate>
<my:AccordionRow runat="server" ID="AccordionRowItem" RowItem="<%# Container.DataItem %>" />
</ItemTemplate>
</asp:Repeater>
And the Row control
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="AccordionRow.ascx.cs" Inherits="mynamespace.Controls.AccordionRow" %>
<sc:EditFrame id="EditAccordionItem" runat="server" Buttons="/sitecore/content/Applications/WebEdit/Edit Frame Buttons/Accordion Item">
<li class="<%= LiClass %>">
<a class="trigger" href="#"><sc:Text runat="server" ID="ItemTitle"/></a>
<div class="collapsible">
<sc:Text runat="server" ID="ItemText" />
</div>
</li>
</sc:EditFrame>
And add a Field Editor Button to the Edit Frame Buttons
More about this Accordion example see User friendly developing with the Sitecore Experience Editor
Or, I often use this simple solution. It also give you the opportunity to display some help text to the content editor.
<div runat="server" id="PageditorDiv" Visible="False">
URl: <sc:Link runat="server" ID="link"/>
</div>
And in the code Behind.
if (Sitecore.Context.PageMode.IsPageEditor)
{
PageditorDiv.Visible = true;
}

restrict data rows in datalist and add a load more button in the footer

datalist is as follows:
<asp:DataList ID="DataListComments" runat="server"
DataKeyField="Pk_Comment_Id" DataSourceID="SqlDataSourceComments" Width="100%">
<HeaderStyle BackColor="Gray" HorizontalAlign="Center" />
<HeaderTemplate>
<asp:Label ID="Label1" runat="server" BackColor="Gray"
ForeColor="White" Text="Comments" Width="100%" />
</HeaderTemplate>
<ItemTemplate>
<div class="CommentBox">
<div class="CommentImage">
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl='<%# "Profile.aspx?uid=" + Eval("fk_User_Id")%>'>
<asp:Image ID="imgUserC" runat="server"
ImageUrl='<%# Eval("Profile_Pic") %>' CssClass="scaling-image" />
</asp:HyperLink>
</div>
<div class="CommentInfo">
<div class="CommentUsername">
<asp:HyperLink ID="linkUserProfile" runat="server"
NavigateUrl='<%# "Profile.aspx?uid=" + Eval("fk_User_Id")%>'><%# Eval("Username") %></asp:HyperLink>
</div>
<div class="CommentDate">(<%# Eval("Date") %>)</div>
<div class="CommentDescription"><%# Eval("Description") %></div>
</div>
</div>
</ItemTemplate>
</asp:DataList>
Now, suppose there are 24 entries for [comments] in the database... I want to show only 3 here... And add a load more button in the footer template, on clicking this load more 5 more comments should be displayed..
If there is a possible solution to this with ajax, i wouldn't have any problem with that. I just need a working solution to this, as I am clueless on how to achieve this.
It's quite complicated when you are using runat server controls like gridview and datalist etc.
To achieve your goal:
You need to create web service
Get records from data base by using the service and JavaScript
Append the result at bottom by using JavaScript
These are things you need to do, and many other problem will start when you will work with server controls.

How to get the parent item index inside child repeater?

I have nested repeaters like this:
<asp:Repeater ID="rptQuestoes" runat="server">
<HeaderTemplate>
<ol class="orderedList">
</HeaderTemplate>
<ItemTemplate>
<li>
<%#DataBinder.Eval(Container.DataItem, "QuestionName")%>
<asp:Repeater ID="rptAlternativas" DataSource='<%# Container.DataItem.Row.GetChildRows("Questionario") %>' runat="server">
<HeaderTemplate>
<ul style="list-style-type: none">
</HeaderTemplate>
<ItemTemplate>
<li>
<input id="rb" type="radio" name='ITEM_INDEX_HERE' value='<%#Container.DataItem("AlternativeID")%>' /><%#Container.DataItem("AlternativeName")%>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
</li>
</ItemTemplate>
<FooterTemplate>
</ol>
</FooterTemplate>
</asp:Repeater>
I want to print the parent item index inside the child repeater (rptAlternativas) in VB right in ITEM_INDEX_HERE marker. How can I achieve this?
I hope someone can give you a better answer than this, but I would consider adding a property to your "Quentionario" sub elements.
<asp:Repeater ID="rptAlternativas"
DataSource='<%# Container.DataItem.Row.GetChildRows("Questionario") %>'
runat="server">
Can you add a question id to each of these objects? You're already binding to their AlternativeId in your radio button, adding a question id to these objects would let you do simply:
<input id="rb" type="radio" name='<%#Container.DataItem("QuestionId")%>' value='<%#Container.DataItem("AlternativeID")%>' />
Even if these objects are auto-generated from an ORM, you should be able to add the property in via a partial class, and then just set the appropriate values in a simple loop.

How to get value of star rating from repeater?

I have an application with star rating.
Star rating inside repeater.
<asp:Repeater ID="reptweet" runat="server" onitemcommand="reptweet_ItemCommand">
<ItemTemplate>
<div class="divtweet">
<span class="box_imag">
<asp:Image ID="ScreenImage" runat="server" ImageUrl='<%#DataBinder.Eval(Container.DataItem,"ImageUrl")%>' height="50" width="50" /></span>
<span class="box_cont">
<div><strong> <a rel="external" href='http://twitter.com/<%#DataBinder.Eval(Container.DataItem,"ScreenName")%>' target="_blank">
<asp:Label ID="lblScreenName" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "ScreenName")%>'></asp:Label></a></strong>
<asp:Label ID="lblText" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "Text")%>'></asp:Label>
</div>
<div class="meta"><asp:Label ID="lblDate" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "Date")%>'></asp:Label></div>
</span>
<asp:UpdatePanel ID="updtpnlTweet" runat="server">
<ContentTemplate>
<cc1:Rating ID="rateTweet" runat="server"
CurrentRating="3"
MaxRating = "5"
StarCssClass="ratingStar"
EmptyStarCssClass="empatyStarRating"
FilledStarCssClass="filledStarRating"
WaitingStarCssClass="savedStarRating"
OnChanged="rateTweet_Changed"
>
</cc1:Rating>
</ContentTemplate>
</asp:UpdatePanel>
<asp:DropDownList ID="DropDownList1" runat="server" Width="100px" CssClass="dropdowntweet" DataSourceID="SqlDataSource1" DataTextField="CategoryName" DataValueField="CategoryId" >
</asp:DropDownList>
</div>
</ItemTemplate>
</asp:Repeater>
Through this code its shows multiple rows and i want sort this repeater content on the basis of star rating.
So can i get the value of star according per row.
Or is there any other way for star rating.
If you are looking for a setup of repeating values broken up into rows a grid view control might make things much easier. A repeater isn't really designed for the concept of date being broken up into logical "rows", it's really made so you can customize the format of your repeating data. Trying to iterate through a repeater is quite a pain in the neck.
With the grid view iterating through your rows is as simple as:
foreach (GridViewRow ratingRow in RatingGrid.Rows)
{
Rating ratingControl;
int rating;
ratingControl = (Rating)(ratingRow.FindControl("rateTweet"));
rating = ratingControl.CurrentRating;
}
Good grid view examples here

Building dynamic links with Repeater control

I am rendering data using Repeater control.
Let's say there are 2 fields in the data source: productName and ProductID
In the following code:
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li>
<%#Eval("productName")%> <br/>
<asp:HyperLink ID="lnkDetails" runat="server" NavigateUrl="~/Details.aspx?ID=">See Details</asp:HyperLink>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
What do I need to modify in
<asp:HyperLink ID="lnkDetails" runat="server" NavigateUrl="~/Details.aspx?ID=">See Details</asp:HyperLink>
to include value retreived from the ProductID in the link NavigateUrl="~/Details.aspx?ID="
NavigateUrl="~/Details.aspx?ID=<%# Eval("productID") %>" should work...
... but it doesn't!
The most elegant way should be:
<asp:HyperLink ID="lnkDetails" runat="server" NavigateUrl='<%# Eval("ProductID", "~/Details.aspx?ID={0}") %>'>See Details</asp:HyperLink>

Resources