我是我轉發的數據源設置爲一個列表(我的產品是一個簡單的類,只包含獲取/ 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