我正在尝试找到一种方法来做一些我认为必须是可能的事情,但我只是错过了这一点 - 所以希望有人可以给我一点推动:)
我正在使用 ASP.NET 中的数据绑定(视图状态已关闭 - 所以在这里和那里使用 controlstate 来处理一些事情)来呈现一个转发器(repeaterPriceClasses),它在每个项目模板(repeaterPriceBands)中都有一个转发器。基本上,这会在每个单元格中从一些文本和一个下拉列表中呈现一个表格。
我正在尝试找到一种方法来枚举按钮的事件处理程序中的 repeaterOuter,以给我一个列表,列出所有原始绑定的元素,这些元素现在有一个值为 >0 的下拉列表,以及该值是什么.
public Dictionary<Price, int> SelectedPrices
{
get
{
var sel = new Dictionary<Price, int>();
foreach(RepeaterItem itemClass in repeaterPriceClasses.Items)
{
var repeaterPriceBands = itemClass.FindControl("repeaterPriceBands") as Repeater;
foreach(RepeaterItem itemBand in repeaterPriceBands.Items)
{
var context = (Price)itemBand.DataItem;
var listQty = itemBand.FindControl("listQty") as DropDownList;
if(listQty.SelectedValue.ToInt32() > 0)
{
sel.Add(context, listQty.SelectedValue.ToInt32());
}
}
}
return sel;
}
}
现在这失败了,因为在数据绑定完成后 itemBand.DataItem 始终为空。
我应该使用什么技术来解决这个问题?
带有主键的隐藏字段(不理想,可能会被滥用并增加页面的权重)
根据索引从原始缓存数据中查找(似乎是错误的)
还是别的/更好的……?
编辑:我可以提供更多信息来帮助解决这个问题吗?