In my codebehind I have:
List<Products> products =
rptr.Datasource = products;
protected string GetVariants(Product product)
{
//
}
In my repeater I have:
<itemTemplate>
<li> <%# Eval("Name") %>
<li> <%# GetVariants(?????????????) %>
</itemTemplate>
How do I pass the product object to the GetVariants method?
(Product)Container.DataItem
应该可以解决问题
Instead of calling back into a method from your markup page, what about creating a new class for binding your Repeater? This avoids the issue all together.
public class RepeaterItem
{
public string Name;
public string Variants;
}
And then bind the Repeater with a new datasource:
List<Products> products = //Get Products
List<RepeaterItem> repeaterItems = new List<RepeaterItem>();
foreach(var product in products)
{
repeaterItems.Add(
new RepeaterItem
{
Name = product.Name,
Variants = GetVariants(product)
});
}
rptr.DataSource = repeaterItems;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.