【发布时间】:2010-06-08 17:44:44
【问题描述】:
我在 FormView 中有一个 ListView,由于某种奇怪的原因,它既不会触发 ItemInsert 也不会触发 ItemCommand 事件。 我正在使用通用列表填充 ListView。我将列表绑定到 OnPreRenderComplete 上的 ListView。
<asp:ListView runat="server" ID="lvReferences" DataKeyNames="idReference" OnItemInserting="ContractReferences_Inserting" OnItemDeleting="ContractReferences_Deleting" InsertItemPosition="LastItem" OnItemCommand="ContractReferences_Command" OnItemCreated="ContractReferences_ItemDataBound">
<LayoutTemplate>
<ul>
<asp:PlaceHolder ID="itemPlaceholder" runat="server" />
</ul>
</LayoutTemplate>
<ItemTemplate>
<li class="obsItem">
<a href="#"><asp:TextBox ID="valRef" runat="server" Width="5px" Enabled="false" Text='<%#Bind("idProcessRecordRef") %>' /></a>
<asp:TextBox id="txtRef" runat="server" Text='<%#Bind("description") %>' />
<asp:ImageButton ID="btDelete" runat="server" CommandName="Delete" ImageUrl="~/_layouts/web.commons/Images/eliminar.png" />
</li>
</ItemTemplate>
<InsertItemTemplate>
<li class="obsItem">
<a href="#"><asp:TextBox ID="valRef" runat="server" Width="5px" Enabled="false" /></a>
<asp:TextBox id="txtRef" runat="server" />
<asp:ImageButton ID="btDetail" CausesValidation="false" OnClientClick="javascript:openPopup();return false;" runat="server" ImageUrl="~/_layouts/web.commons/Images/novo.png" />
<asp:ImageButton ID="btSaveDs" runat="server" CommmandName="Insert" CausesValidation="false" ImageUrl="~/_layouts/web.commons/Images/gravarObs.png" />
</li>
</InsertItemTemplate>
</asp:ListView>
我的 ItemDataBound 方法是:
protected void ContractReferences_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (!IsPostBack)
{
TextBox valRef = e.Item.FindControl("valRef") as TextBox;
TextBox txtRef = e.Item.FindControl("txtRef") as TextBox;
ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "function openPopup(){ window.open('ContractPicker.aspx?c1=" + valRef.ClientID + "&c2=" + txtRef.ClientID + "');}", true);
}
}
因此,基本上,我在 InsertItemTemplate 中放置了一个按钮,用于打开 LOV 并填充我的 valRef 和 txtRef 字段。我必须输入“return false”才能使父页面不回发(我认为问题出在此处……)。 然后,当我单击带有 CommandName="Insert" 的 ImageButton 时,它不会触发 ItemCommand 事件,而是再次进入 ItemDataBound 处理程序。
那么,有什么想法吗?
谢谢!
【问题讨论】:
-
顺便说一句,构建复杂的字符串建议尝试
String.Format() -
是的,我知道,我在使用 String.Format 时遇到了一个严重的错误,所以我在这方面浪费了很多时间,我用连接构建了字符串,直到我解决了这个错误。
标签: c# asp.net listview postback