我通过编程方式通过查询Web部件构建了一个内容。问题是,当我部署解决方案时,Web部件不会自动更新项目。我必须去“编辑webpart”,然后按 ok ,仅此而已。然后它更新,我可以看到我的项目。我尝试过使用UseCatch = false
,正如您在下面的代码中看到的那样,但它无效:
public void contentQuery(SPWeb web, SPList list)
{
ContentByQueryWebPart queryWP = new ContentByQueryWebPart();
//Properties
queryWP.Title = "Aktuella Dokument";
queryWP.ChromeType = PartChromeType.TitleAndBorder;
//Query from list
queryWP.ListName = list.ID.ToString("B").ToUpper();
queryWP.ListGuid = list.ID.ToString("B").ToUpper();
queryWP.WebUrl = web.ServerRelativeUrl;
//Query field
SPField fieldToQuery = list.Fields.GetFieldByInternalName("Aktuellt");
string fieldAsString = fieldToQuery.ToString();
string FieldValue = fieldToQuery.DefaultValue;
//queryWP.ListsOverride = fieldAsString;
queryWP.AdditionalFilterFields = fieldAsString;
queryWP.FilterField1 = fieldAsString;
queryWP.FilterOperator1 = ContentByQueryWebPart.FilterFieldQueryOperator.Eq;
queryWP.FilterValue1 = FieldValue;
queryWP.InitialAsyncDataFetch = true;
queryWP.UseCache = false;
AddWebPart(queryWP, web, "TopColumnZone", 0);
}