ASP.Net の詳細ビュー コントロールがあります。その DataSourceId はさまざまで、それに応じて Page_load に設定します... (LLBLgen サブタイプに基づいていますが、これはあまり重要ではありません)
これは、 「取得」していないページライフサイクルの漏れやすい抽象化だと思います。
問題は、データソースに応じて存在する場合と存在しない場合があるフィールドにバインドすることです...
特定の条件下でバインドされたフィールドを「無効にする」ために、分離コードで表示または非表示に設定したパネルでバインドされたフィールドをラップしようとしましたが、それでも次のエラーが発生します。
Sys.WebForms.PageRequestManagerServerErrorException: DataBinding: エンティティに 'FilePrefix' という名前のプロパティが含まれていません。
ページロードで detaislview.datasourceid を変更します...ライフサイクルでは遅すぎる可能性があります。
新しいデータソースには存在しないため、そのフィールドにバインドしたくありませんが、それでもバインドしようとするとエラーが発生します。
何か案は?;)
[編集]: 要求どおりのコード...
ASP、詳細ビュー バインド列:
<asp:TemplateField>
<ItemTemplate>
<asp:Panel ID="pnlNormalAdditionalFields" runat="server" Visible="false">
<asp:textbox id="txtFilePrefix" runat="server" MaxLength="250" Width="180px" text='<%# Bind("FilePrefix") %>'></asp:textbox>
<asp:requiredfieldvalidator id="valFilePrefix" runat="server" errormessage="File Prefix is required." controltovalidate="txtFilePrefix">*</asp:requiredfieldvalidator>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
コード ビハインド: (データソースを決定します。detaislview はポストバック時にのみ表示され、最初のページ ロードでグリッドが表示されます。)
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack) //initial load
{
}
else //postback
{
//set customdatasource for grid & detailsview
switch (radAccountType.SelectedValue)
{
case "Normal":
dvAccount.DataSourceID = "NormalCollectionDataSource";
AccountRadGrid.customDataSourceId = "NormalCollectionDataSource";
break;
case "Reseller":
dvAccount.DataSourceID = "ResellerCollectionDataSource";
AccountRadGrid.customDataSourceId = "ResellerCollectionDataSource";
break;
...
パネルの表示/非表示:
protected void dvAccount_OnPreRender(object sender, EventArgs e)
{
Panel pnlGroupStoreAdditionalFields = ControlHelper.FindControlFromTop(this, "pnlGroupStoreAdditionalFields", null) as Panel;
pnlGroupStoreAdditionalFields.Visible = false;
switch (radAccountType.SelectedValue)
{
...
case "GroupStore":
ddlAccountType.SelectedValue = Constants.Account.Type.GroupStore;
pnlGroupStoreAdditionalFields.Visible = true;
break;
}
}
}