2012-02-20 7 views
0

私は(別のリストビュー内に)埋め込まれたリストビューを持っていて、両方のリストビューがCRUD操作を正常に許可しています。埋め込みリストビュー内でDynamicControlを使用しているASP.NET 4.0

埋め込まれたリストビューのためのASPは、次のようになりますように埋め込まれたのObjectDataSourceの選択パラメータのデフォルト値を設定する外リストビューのonItemDataBoundイベントに

<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"> 

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は、データアクセス層でエンティティフレームワークを使用します。私はインナー(ネストされた)リストビューに動的なコントロールに任意のコントロールを変更するときdynamicControlsは、外側(非ネストされた)リストビューに完全に取り組んでいますが

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; } 
    } 
} 

:私はそうと、エンティティクラスのdataAnnotationsを設定しています、私はエラーを取得する:

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

私はこれを見ていないと信じられません - 私は誰の時間を無駄にして申し訳ありません。

Page_Initは、外側のListViewのEnableDynamicDataを設定している間、私はネストされたリストビューのためのOnInitハンドラを使用する必要があります。

protected void infusionConcLV_init(object sender, EventArgs e) 
    { 
     ListView thisLV = (ListView)sender; 
     thisLV.EnableDynamicData(typeof(infusionConcentration)); 
    } 
関連する問題