ASP.NET アプリケーションを構築しています。ListView を使用していくつかのエンティティを表示していますが、リストビューには最初のパスにアイテムがありません。つまり、それらはページに表示されますが、このコードはページを更新したときにのみ機能します。
protected void Page_Load(object sender, EventArgs e)
{
    fillFeatures();
}
private void fillFeatures()
{
    using (Entities myEntities = new Entities())
    {
        System.Diagnostics.Debug.Write("Filling features.. \n");
        foreach (ListViewItem item in ListView1.Items)
        {
            System.Diagnostics.Debug.Write("FOR \n");
            CheckBox checkbox = (CheckBox)item.FindControl("Checkbox");
            TextBox description = (TextBox)item.FindControl("descriptionTextbox");
            //Try to get an existing relation
            int featureId = Int32.Parse(((Label)item.FindControl("idLabel")).Text);
            PlaceHasFeature phf = (from p in myEntities.PlaceHasFeature
                                   where p.place_id == placeId && p.feature_id == featureId
                                   select p).SingleOrDefault();
            if (phf != null)
            {
                System.Diagnostics.Debug.Write("Checking " + phf.Feature.name + "\n");
                //Relation exists
                checkbox.Checked = true;
                description.Text = phf.description;
            }
            else
            {
                System.Diagnostics.Debug.Write("Didn't find relation for " + featureId + "\n");
            }
        }
    }
}
コンソール出力:
リンクを開くと: Filling features...
更新後: 特徴を埋めています... FOR FOR FOR (...)
誰でもこれの原因を知っていますか?