我是我转发的数据源设置为一个列表(我的产品是一个简单的类,只包含获取/ setter方法)。的DataItem上Repeater.Items总是空
这个和的DataBind(),我可以在调试模式下,每个Repeater.Items的DataItem的是空见后。在进行回发并尝试更新MyProducts时,Repeater.Items [n] .DataItem仍然为空,我无法投射它,以完成我的工作。
为什么DataItem在每个RepeaterItem上设置,当我绑定我的中继器时?我不知道/谷歌它。我的代码每隔方面正常工作(从我的产品到ASPX输出数据,例如使用:
<asp:TextBox runat="server" id="q" Text='<%# DataBinder.Eval(Container.DataItem, "Quantity")%>'></asp:TextBox>
更多代码:
public class MyProducts
{
public string Number
{
get; set;
}
public decimal Price
{
get; set;
}
public decimal Quantity
{
get; set;
}
public decimal Total
{
get { return Quantity * Price; }
}
}
生成:
public List<MyProducts> TheProducts
{
get { // Invoking webservice, getting response as xml and converting it to a list of MyProducts }
}
我的用户控件:
// Bind products in cart
r.DataSource = TheProducts;
r.DataBind();
// Debugging "r.Items[n].DataItem" now shows "null", eventhough all objects has been correctly binded
编辑#2,调试信息。 DataSource被正确加载,但Repeater.Items [3] .DataItem为null。它应该有一个价值,对吧? screenshot
编辑#3, 我现在明白了,我还以为是DataItem的数据源时设置总是可访问的,没想到的,包括完整的代码(我试图访问它在Page_Load中)的。用户编辑的数量值
后,我想保存新数量为我的产品。我通过放置一个包含MyProducts id的hiddenfield来解决这个问题,以便我可以手动查找它并从那里获取MyProducts对象。
感谢emremp,马克Avenius和所有其他谁英寸
你也许能给我们一些代码... – 2010-10-08 08:36:45
工作,我已经编辑我的职务,并插入更多的代码。虽然它非常基本,但我不认为它会给出任何澄清。我曾“希望”我错过了一些简单的东西,有人可以为我指出。我发现它非常奇特,我可以绑定MyProduct对象,但DataItem为空... – Certs 2010-10-08 08:47:53
你想在这里实现什么?你的“数量”是否被绑定到中继器? – bla 2010-10-08 08:57:21