我收到ListView控件Item Inserted事件的异常。我有字段城市值由数据表下拉列表控件填充。
>应用程序中的服务器错误。此控件的插入功能已禁用。 描述:执行当前Web请求期间发生未处理的异常。 >请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。 异常详细信息:System.InvalidOperationException:对此控件禁用插入。
来源错误: 在执行当前Web请求期间生成了未处理的异常。可以使用下面的异常堆栈>跟踪来识别关于异常的起源和位置的信息。
堆栈跟踪: [InvalidOperationException:此控件禁用插入。] System.Web.UI.WebControls.EntityDataSourceView.ExecuteInsert(IDictionary values)+88405 System.Web.UI.DataSourceView.Insert(IDictionary values,DataSourceViewOperationCallback> callback)+81 System.Web.UI.WebControls.ListView.HandleInsert(ListViewItem item,Boolean causeValidation)> +716 System.Web.UI.WebControls.ListView.HandleEvent(EventArgs e,Boolean causeValidation,String> validationGroup)+1333 System.Web.UI.WebControls.ListView.OnBubbleEvent(Object source,EventArgs e)+315 System.Web.UI.Control.RaiseBubbleEvent(Object source,EventArgs args)+37 System.Web.UI.WebControls.ListViewItem.OnBubbleEvent(Object source,EventArgs e)+141 System.Web.UI.Control.RaiseBubbleEvent(Object source,EventArgs args)+37 System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e)+114 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)+159 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String> eventArgument)+10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl,String eventArgument)> +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)+35 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean> includeStagesAfterAsyncPoint)+1724
标记如下
<asp:ListView ID="LstVwCompanyDetails" runat="server" DataSourceID="EntDatSrcCompanyDetails"
ClientIDMode="Static" DataKeyNames="YPCode" InsertItemPosition="LastItem"
OnItemInserting="LstVwCompanyDetails_ItemInserting"
>
..............
..............
<InsertItemTemplate>
<table style="box-shadow: 5px 2px 10px black;background-color: darkolivegreen; color: ghostwhite;">
<tr>
<td>
<asp:TextBox ID="County" runat="server" Text='<%# Bind("County") %>' />
</td>
<td>
<asp:DropDownList ID="ddlCityList" runat="server" AppendDataBoundItems="True" AutoPostBack="True" DataSourceID="EntDataSrcSelectedCities" DataTextField="city" DataValueField="cityID" ClientIDMode="Static">
</asp:DropDownList>
</td>
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" ToolTip="Add details" Text="Add" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" />
The code in ItemInserting event handler is
==================
protected void LstVwCompanyDetails_ItemInserting(object sender, ListViewInsertEventArgs e)
{
DropDownList ddlCity = (DropDownList)LstVwCompanyDetails.InsertItem.FindControl("ddlCityList");
//e.Item.FindControl("ddlCityList") as DropDownList;
if (ddlCity != null)
{
e.Values["CompanyCode"] = (Convert.ToInt32(ddlCity.SelectedValue));
}
}
===============
谢谢 内特