Show RadListBoxItem Without Template - asp.net

I have the following Telerik RadListBox, with a template.
<tel:RadListBox ID="ToList" runat="server" DataValueField="Key" EmptyMessage="No Items" style="width:300px;">
<ItemTemplate>
#<asp:Literal runat="server" Text='<%# Eval("AcctNumber") %>' />
<div>
<asp:Literal runat="server" Text='<%# Eval("Amount", "{0:C2}") %>' />
</div>
</ItemTemplate>
</tel:RadListBox>
However, I'd like to insert a blank "- Select -" item at the beginning. I tried adding an item like:
ToList.Items.Insert(0, new RadListBoxItem("- Select -", ""));
However, this adds an item using the given template as the user interface; I'd like it ot use my text. Is this possible to do?

Luckily, there is an easy solution. Put an inline conditional statement in the ItemTemplate, as follows:
<ItemTemplate>
<ul>
<li class="col1"><%# Container.DataItem != null ? DataBinder.Eval(Container.DataItem, "CompanyName") : DataBinder.Eval(Container, "Text") %></li>
<li class="col2"><%# DataBinder.Eval(Container.DataItem, "City") %></li>
<li class="col3"><%# DataBinder.Eval(Container.DataItem, "ContactTitle") %></li>
</ul>
</ItemTemplate>
<Items>
<telerik:RadComboBoxItem Text="Select a country" />
</Items>
http://www.telerik.com/help/aspnet-ajax/combobox-insert-default-item-when-databinding.html

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

Dynamic menu with ASP.NET repeater

Currently i'm familiarizing myself with ASP.NET and i've stuck on a problem with dynamic content inside "ItemTemplate" of "Repeater". Here is my code:
<asp:Repeater ID="sidebarRepeater" runat="server">
<ItemTemplate>
<li>
<%# DataBinder.Eval(Container.DataItem, "Name") %>
</li>
</ItemTemplate>
</asp:Repeater>
I'm getting a list of links with href == Id of current item and text of this item.
The problem is, that i need a "Onclick" asp.net handler for each of those links (this is menu of "Master" User control, and on each click i shall change contents of child user control, according to selected item in master).
Any tips?
Edit: I've already tryed to use LinkButton like:
<li>
<asp:LinkButton ID='<%# DataBinder.Eval(Container.DataItem, "Id") %>' runat="server" OnClick="ChangeSomething">
<%# DataBinder.Eval(Container.DataItem, "Name") %>
</asp:LinkButton>
</li>
Edit2: Currently my markup looks like this:
<li>
<input type="hidden" value="<%# DataBinder.Eval(Container.DataItem, "Id") %>"
<asp:LinkButton runat="server" ID="LinkButton_Office" Text='<%# DataBinder.Eval(Container.DataItem, "Name") %>'/>
</li>
In this case, it draws only a "hidden input" element only for first item in repeater.
Edit3: full listing of what i currently have(only <li></li> rendered into actual HTML):
<div class="row">
<div class="twelve column">
<div class="row">
<div class="side-bar">
<nav>
<ul>
<asp:Repeater ID="sidebarRepeater" runat="server">
<ItemTemplate>
<li>
<asp:LinkButton ID="linkSidebar" runat="server" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "Id") %>' Text='<%# DataBinder.Eval(Container.DataItem, "Name") %>' OnClick="linkMenu_Click"></asp:LinkButton>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
</nav>
</div>
<div class="page">
<asp:PlaceHolder runat="server" ID="contentPlaceholder" />
</div>
</div>
</div>
</div>
Also i forgot to say, that this is actually a .Net user control for Umbraco project.
Datasource is attached for repeater in protected void Page_Load(object sender, EventArgs e) method.
Please try like this
<asp:Repeater ID="sidebarRepeater" runat="server">
<ItemTemplate>
<asp:LinkButton ID="linkMenu" runat="server" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "Id") %>' Text='<%# DataBinder.Eval(Container.DataItem, "Name") %>' OnClick="linkMenu_Click"></asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
This will keep "Id" field in CommandArgument and "Name" field in Text properties
In linkMenu_Click event handeler, you will get the Id and Name values as the sample code
protected void linkMenu_Click(object sender, EventArgs e)
{
LinkButton link = (LinkButton)sender;
string id = link.CommandArgument;
string name = link.Text;
//Implement the different display of each menu here ...
}
Problem solved, by adding <form runat="server"> around my <nav> tag.
Seems like every of <asp:button\linkbutton> needs that in order to work properly.

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.

binding a dictionary to a repeater using <a> tag

<asp:Repeater ID="rptAlbum" runat="server">
<ItemTemplate>
<a runat="server" href="<%# DataBinder.Eval("key")) %>" rel='lightbox[<%#Eval("value") %>]'>
<asp:Image ID="Image1" runat="server" ImageUrl='<%#Eval("key") %>' Width="30px" Height="30px"/>
</a>
</ItemTemplate>
</asp:Repeater>
I try many way to catch the key of the dictionary into my href but allways give me answer that server tag not well formed or a string doesn't have the property of key .. :s
If someone could help me it would be very helpfull :)
best regards
Your outer quotes where wrong:
<asp:Repeater ID="rptAlbum" runat="server">
<ItemTemplate>
<a runat="server" href='<%# DataBinder.Eval("key")) %>' rel='lightbox[<%#Eval("value") %>]'>
<asp:Image ID="Image1" runat="server" ImageUrl='<%#Eval("key") %>' Width="30px" Height="30px"/>
</a>
</ItemTemplate>
</asp:Repeater>
you can't use that : since its a with runat server. it cant contains another yellow code in it ( only in the internal text of it)
<a href="<%# DataBinder.Eval("key")) %>" rel='lightbox[<%#Eval("value") %>]'>
<asp:Image ID="Image1" runat="server" ImageUrl='<%#Eval("key") %>' Width="30px" Height="30px"/>
</a>
important :
this is fine :
<a runat="server " >
<%# DataBinder.Eval("lalala")) %>
</a>
this is wrong
<a runat="server " something='<%# DataBinder.Eval("lalala")) %>' > //here is the error - it contains a yellow code inside the runat server DECLARATION of the element
<%# DataBinder.Eval("lalala")) %>
</a>

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