私はASP.NETアプリケーションを構築しています。 ListViewを使っていくつかのエンティティを表示していますが、リストビューには最初のパスに項目がありません。私が意味する、彼らはページ上に表示されますが、私はページを更新すると、このコードは動作します:最初のパスにアイテムのない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");
}
}
}
}
コンソール出力:
私はリンクを開く:充填の機能を...
リフレッシュ後:フィーチャーの記入...(...)
誰でもこの原因が分かりますか?
ListView1.ItemsはPage_Loadイベントの後に設定されているようです。これはすべてコードですか?通常は、fillFeaturesを1回だけ呼び出すだけです。これもあなたが望むだろうか? Page_LoadのfillFeatures呼び出しをif(!PostBack){fillFeatures();のようにラップします。 }。 –
ListView1.Itemsは、私の介入なしにEntityDataSourceによって設定されます。 if(!isPostBack)を置くと、チェックボックスがいっぱいになりません。 –
はい、これはPage_Loadで発生するすべてのコードです。残りはSubmitButtonのイベントです。 –