How to get the parent item index inside child repeater? - asp.net

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.

Related

Get checkboxes in repeater header template

I need to access some checkboxes that are inside the header template of my repeater.
Actually they are outside of it and in the code behind they are accessed using the keyword "this". I cannot change all the code and i must mantain the same logic. The issue is that if i move the checkboxes inside the header of the repeater, i cannot find them using "this".
I've something like this:
<div id="containerListNotify" style="padding-left: 5px;">
<asp:UpdatePanel ID="UpdatePanelRepListNotify" runat="server" UpdateMode="Conditional" ClientIDMode="Static">
<ContentTemplate>
<asp:HiddenField ID="iconsHiddenField" runat="server" ClientIDMode="Static" />
<asp:Repeater ID="repListNotify" runat="server" OnItemCommand="RepListNotify_ItemCommand"
OnItemDataBound="RepListNotify_ItemCreated">
<HeaderTemplate>
<table id="tableCentroMessaggi" class="table table-hover">
<thead>
<tr id="HeaderMessaggi">
<th>
<%--<asp:Label runat="server" ID="docFascCol" Text='<%#this.getDocFascColText() %>' />--%>
<div class="dropdown">
<button onclick="openCloseDocFascDropdown()" class="dropbtn"><asp:Label runat="server" ID="docFascCol" Text='<%#this.getDocFascColText() %>' /><b class="caret"></b></button>
<div id="docFascDropdown" class="dropdown-content">
<ul>
<li>
<asp:CheckBox ID="IndexCheckDoc" CssClass="clickableLeftN" Checked="true" runat="server"
AutoPostBack="true" OnCheckedChanged="IndexCkbFilterObject_CheckedChanged" />
</li>
<li>
<asp:CheckBox ID="IndexCheckProj" CssClass="clickableLeftN" Checked="true" runat="server"
AutoPostBack="true" OnCheckedChanged="IndexCkbFilterObject_CheckedChanged" />
</li>
<li>
<asp:CheckBox ID="IndexCheckOther" CssClass="clickableLeftN" Checked="true" runat="server"
AutoPostBack="true" OnCheckedChanged="IndexCkbFilterObject_CheckedChanged" />
</li>
</ul>
</div>
</div>
</th>
<th>
The important thing is that i need to access them even in private methods and not only in event methods.
I hope that there is a solution to this. I guess i can use "FindControl".
This .aspx uses a MasterPage.
Thanks in advance.
If you want to access Controls that are inside another control like Repeater, GridView etc. you're gonna have to use FindControl with and item/row index. Where you access them does not matter.
CheckBox IndexCheckDoc = repListNotify.Controls[0].Controls[0].FindControl("IndexCheckDoc") as CheckBox;
CheckBox IndexCheckProj = repListNotify.Controls[0].Controls[0].FindControl("IndexCheckProj") as CheckBox;
CheckBox IndexCheckOther = repListNotify.Controls[0].Controls[0].FindControl("IndexCheckOther") as CheckBox;

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;
}

dynamically change css class name

Below is my code:
<asp:ListView ID="lViewMenu" runat="server">
<ItemTemplate>
<li class="context-menu-group"><span class="color-bar color-13"></span>
<asp:LinkButton ID="lbtnMenu" runat="server" Text='<%# Eval("MenuName")%>' OnClick="lbtnMenu_Click"></asp:LinkButton>
</li>
</ItemTemplate>
</asp:ListView>
And i need to change the class name of <li> to context-menu-group active when a LinkButton is clicked on the onclick() How?

Displaying information using repeater

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

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