2014-05-12 67 views
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”,但文字未被更新。

我在做什么错了,该怎么做才能正确更新它?

谢谢

回答

0

对于之前的代码,我假设ListView为Listbox,对不起。 Actucally它将永远无法找到列表视图中的文本框。

虽然有一点是肯定的,你需要在<ContentTemplate>之外写<trigger>

您使用Listview的任何特定原因。如果你可以使用Listbox/Grid?

+0

你的方法引发了一个异常:在UpdatePanel'UpdatePanel'中找不到触发器的ID为'Units'的控件。 –

+0

ok让我再次检查 –

+0

请检查我编辑的答案 –

相关问题