Building dynamic links with Repeater control - asp.net

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>

Related

How i can display top 3 record

I have a repeater in an ASP.NET website that I want to only show the 3 record
Repeater:
<asp:Repeater ID="repNews" runat="server" DataSourceID="EntityDataSource1">
<ItemTemplate>
<ul>
<li><a href='<%# Eval("news_link")%>' > <asp:Label ID="lblNews" runat="server" Text='<%# Eval("news_title")%>' /></a></li>
</ul>
</ItemTemplate>
and The entity Model
</asp:Repeater>
<asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=AGIP_dbEntities" DefaultContainerName="AGIP_dbEntities" EnableFlattening="False" EntitySetName="tbl_news" >
</asp:EntityDataSource>
thanks guys but i try this and this work
Select="top(2) it.news_title,it.news_link"
add it in entitydatasoruce
will be like this
<asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=AGIP_dbEntities" DefaultContainerName="AGIP_dbEntities" EnableFlattening="False" EntitySetName="tbl_news" Select="top(2) it.news_title,it.news_link">
</asp:EntityDataSource>

hyper link button Target __blank not working while click image within repeater control

My asp code like this
<asp:Repeater ID="Repeater1" runat="server" Visible="true">
<ItemTemplate>
<asp:HyperLink ID="imgbtnHl" runat="server" Target="_blank"> // hyper link btn am givem target equal to blank but it is not working/
<asp:ImageButton runat="server" Width="300px"ID="imgbtnHospitalimg" ImageUrl=images/tt.png" />/while click the image i want new window not an popup/
</asp:HyperLink>
Don't use image button inside hyperlink instead of that use simple img tag.
referrer below code i have tested working fine.
<asp:Repeater ID="Repeater1" runat="server" Visible="true">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" Target="_blank" NavigateUrl="~/Default3.aspx" Text='<%# Eval("Name") %>'><img src="Good-mark.png" /></asp:HyperLink>
</ItemTemplate>
</asp:Repeater>

Show RadListBoxItem Without Template

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

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

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.

Resources