0
我一直在解決我的問題,但我似乎沒有找到解決我的問題的充分辦法。我有以下的代碼:如何在ListView中正確使用UpdatePanel?
<asp:ScriptManager EnablePartialRendering="true" ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:ListView ID="productList" OnItemDataBound="pharmaciesList_ItemDataBound" runat="server">
<ItemTemplate>
<asp:TextBox CssClass="span1" ID="Units" runat="server" AutoPostBack="true" OnTextChanged="Units_TextChanged" />
<asp:Literal runat="server" ID="Discount" />
</ItemTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Units" EventName="TextChanged" />
</Triggers>
</asp:ListView>
後面的代碼:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
productList.DataSource = this.LineItems;
DataBind();
}
}
protected void Unidades_TextChanged(object sender, EventArgs e)
{
TextBox qtt = (TextBox)sender;
var parent = qtt.Parent;
while (!(parent is IDataItemContainer))
parent = parent.Parent;
ListViewDataItem listitem = parent as ListViewDataItem;
Literal lit = listitem.FindControl("Descuento") as Literal;
lit.Text = "A";
}
每個項目包含了單位的文本框,並應與新的折扣取決於量進入更新的文字(用於測試的目的,我只是希望這個標籤暫時變成「A」)。即使在使用調試器之後,在更改該列表中的文本框之後執行lit.Text =「A」,但文字未被更新。
我在做什麼錯了,該怎麼做才能正確更新它?
謝謝
你的方法引發了一個異常:在UpdatePanel'UpdatePanel'中找不到觸發器的ID爲'Units'的控件。 –
ok讓我再次檢查 –
請檢查我編輯的答案 –