タグDropDownList
を使用して作成した にデータをバインドしようとしています。<asp:DropDownList
最初の については正常に機能しDropDownList
ますが、残りの 2 については例外がスローされます。データ ソースがnull ではなく、実際に値を持っていることはわかっているので、他の 2 つのリスト ボックスがまだロードまたはバインドされていないことしか考えられません。
メソッドを使用してコンテンツを追加しようとしましたPage_LoadComplete
が、起動していないようです。私は MVC に慣れていて、Web フォームに慣れていないので、何が間違っているのかわかりません。要素がまだロードされていないと述べて正しいですか?もしそうなら、要素がロードされたらどうすればそれらをバインドできますか?
protected void Page_Load(object sender, EventArgs e)
{
//Page.LoadComplete += new EventHandler(Page_LoadComplete);
if (DataContext == null)
{
DataContext = new ReuseLibraryDataContext(SPContext.Current.Web.Url);
}
// top level category for all documents
_functions = DataContext.ReuseLibrary.Select(p => p.FunctionalCategories).Distinct().ToList();
// the first sub category
_sc1 = DataContext.ReuseLibrary.Select(p => p.SubCategoriesLevel1).Distinct().ToList();
// the second sub category
_sc2 = DataContext.ReuseLibrary.Select(p => p.SubCategoriesLevel2).Distinct().ToList();
// add the functions to the dropdown
listFunctions.DataSource = _functions;
listFunctions.DataBind();
// add the sub cat 1 to the dropdown
listSC1.DataSource = _sc1;
listSC1.DataBind();
// add the sub cat 2 to the dropdown
listSC2.DataSource = _sc2;
listSC2.DataBind();
}
//protected void Page_LoadComplete(object sender, EventArgs e)
//{
// // add the functions to the dropdown
// listFunctions.DataSource = _functions;
// listFunctions.DataBind();
// // add the sub cat 1 to the dropdown
// listSC1.DataSource = _sc1;
// listSC1.DataBind();
// // add the sub cat 2 to the dropdown
// listSC2.DataSource = _sc2;
// listSC2.DataBind();
//}