我有一个嵌入式列表视图(在另一个列表视图中),两个列表视图都成功地允许CRUD操作。
嵌入式列表视图的asp如下所示:
<asp:ObjectDataSource ID="objConcentrations" runat="server"
TypeName="PICUdrugs.BLL.infusionBL" DataObjectTypeName="PICUdrugs.DAL.infusionConcentration"
InsertMethod="insertConcentration" SelectMethod="getConcentrations"
deleteMethod="deleteConcentration" UpdateMethod="updateConcentration"
OldValuesParameterFormatString="orig{0}" ConflictDetection="CompareAllValues"
OnUpdated="objConcentrations_CRUD" OnInserted="objConcentrations_CRUD">
<SelectParameters>
<asp:Parameter Name="infDilutionID" Type="Int32"/>
</SelectParameters>
</asp:ObjectDataSource>
<asp:ListView ID="infusionConcListView" runat="server" DataSourceID="objConcentrations"
ItemPlaceholderID="itemPlaceHolder1" InsertItemPosition="LastItem" DataKeyNames="infusionConcentrationID"
OnDataBound="concentrationLV_allDataBound" EnableViewState="False">
使用外部listview的onItemDataBound事件设置嵌入的objectDataSource上select参数的默认值,如下所示:
protected void infDilutnLV_itemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
ObjectDataSource infConcentrations = e.Item.FindControl("objConcentrations") as ObjectDataSource;
ListViewDataItem dataItem = (ListViewDataItem)e.Item;
if (infConcentrations != null)
{
infusionDilution infDil = (infusionDilution)dataItem.DataItem;
Parameter parameter = infConcentrations.SelectParameters[0];
parameter.DefaultValue = infDil.infusionDilutionID.ToString();
}
}
}
然后,objectDataSource在数据访问层中使用实体框架。我已经为实体类设置了dataAnnotations:
namespace PICUdrugs.DAL
{
[MetadataType(typeof(infusionDilutionMetaData))]
public partial class infusionDilution
{
}
public class infusionDilutionMetaData
{
[Range(0, 3000, ErrorMessage = "volume must be between 0 and 3000 ml")]
public int? finalVol { get; set; }
}
[MetadataType(typeof(infusionConcentrationMetaData))]
public partial class infusionConcentration
{
}
public class infusionConcentrationMetaData
{
[Range(0.001, 1000, ErrorMessage = "concentration must be between 0.001 and 1000 units/ml")]
public double Concentration { get; set; }
}
}
虽然dynamicControls在外部(非嵌套)列表视图上完美运行,但当我将任何控件更改为内部(嵌套)列表视图上的动态控件时,我收到错误:
Could not determine a MetaTable. A MetaTable could not be determined for the data source 'objConcentrations' and one could not be inferred from the request URL. Make sure that the table is mapped to the dats source, or that the data source is configured with a valid context type and table name, or that the request is part of a registered DynamicDataRoute.
我担心我非常喜欢业余程序员,我不确定是否可以在嵌套列表视图中使用dynamicFields。有没有变通办法,或者我的代码中是否有错误?非常感谢您的帮助。
答案 0 :(得分:0)
我无法相信我没有看到这个 - 抱歉,如果我浪费了任何人的时间。
当Page_Init设置外部ListView的EnableDynamicData时,我需要为嵌套的ListView使用onInit处理程序:
protected void infusionConcLV_init(object sender, EventArgs e)
{
ListView thisLV = (ListView)sender;
thisLV.EnableDynamicData(typeof(infusionConcentration));
}