我有一个ASP.Net detailsview控件。它的DataSourceId变化,我相应地设置在Page_load ...(基于LLBLgen子类型,但这不是太重要)如何有条件地禁用detailsview数据绑定字段
我想这是一个页面生命周期leaky abstraction我不是“得到”。
的问题是,我绑定到字段可能会或可能不会是有依据的数据源...
为“Disable”在一定条件下绑定的字段我已经试过包装在一个绑定字段面板,我设置为可见或不可见的代码隐藏,但我仍然得到以下错误:
Sys.WebForms.PageRequestManagerServerErrorException:DataBinding:实体不包含名称为'FilePrefix'的属性。
我更改pageload中的detaislview.datasourceid ...可能在生命周期中太晚了。
我不想绑定到该字段,因为它不存在新的数据源,但它试图做到这一点,我得到的错误。
任何想法? )
[被修改]:作为请求码...
ASP,DetailsView的绑定的列:
<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;
}
}
}
你可以发布一些代码吗? – 2010-05-19 12:44:46