1
我想在ASP.NET中以編程方式更改DynamicControl模式。 我已經嘗試過兩種方法,但我兩次都失敗了。 首先我試着在代碼後面執行它。 DynamicControls模式設置爲「編輯」。在頁面加載時,我重複了控制並試圖改變這種模式ASP.NET:如何以編程方式更改DynamicControl模式
((DynamicControl)c).Mode = DataBoundControlMode.ReadOnly;
這並沒有產生任何結果。
在第二種方法中,我在aspx頁面中使用了內聯表達式。
Mode= "<%#getDynamicControlMode(MPFormView) %>"
和在代碼中使用的功能後面是
public DataBoundControlMode getDynamicControlMode(FormView fv)
{
if (fv.CurrentMode == FormViewMode.ReadOnly)
return DataBoundControlMode.ReadOnly;
else if (fv.CurrentMode == FormViewMode.Edit)
return DataBoundControlMode.Edit;
else
return DataBoundControlMode.Insert;
}
這種方法也失敗了,控制留在只讀模式無論FormViewMode的。 我想做這個programaticall,因爲我想在FormView中只使用一個模板。 謝謝