0
我創建了公共類HeroImage和ExpandedHomeSlider來訪問一個自定義列表,該列表將被賦予給Repeater以便允許修改SPListItem。 如何將我的屬性從ExpandedHomeSlider類綁定到SPListItemCollection?我是SP開發新手。任何幫助表示讚賞:]。如何將我的屬性從ExpandedHomeSlider類綁定到SPListItemCollection?
public partial class HomePageHeroRotator : UserControl
{
public SPListItem SpListItem;
public class HeroImage
{
public SPListItem SpListItem;
public string heroImageUrl
{
get { return SpListItem["HeroImage"].ToString(); }
}
public string heroImageUrl2
{
get { return SpListItem["HeroImageCallOut"].ToString(); }
}
}
public class ExpandedHomeSlider
{
public SPListItem SpListItem;
public string explanatoryText
{
get { return SpListItem["ExplanatoryText"].ToString(); }
}
public string attentionExplanatoryText2
{
get { return SpListItem["ExplanatoryText"].ToString(); }
}
public string explanatoryText2
{
get { return SpListItem["ExplanatoryText"].ToString(); }
}
public string homeSliderImageUrl
{
get { return SpListItem["ExpandedSliderImage"].ToString(); }
}
public string GreenFlyoutText
{
get { return SpListItem["GreenFlyoutText"].ToString(); }
}
}
protected void Page_Load(object sender, EventArgs e)
{
//Query List for all List Items
//ASCX to render list items
SPSite site = null;
if (SPContext.Current != null)
{
site = SPContext.Current.Site;
}
SPList list = site.RootWeb.Lists["HomePageHero"];
SPListItemCollection myItems = list.Items;
IEnumerable eList = myItems.Fields as IEnumerable;
//foreach loop
HomePageHeroRpt.DataSource = eList;
HomePageHeroRpt.DataBind();
}
我Schema.xml的列表中包含了以下字段:
<ViewFields>
<FieldRef Name="LinkTitle" />
<FieldRef Name="ExplanatoryText" />
<FieldRef Name="GreenFlyoutText" />
<FieldRef Name="BrownFlyoutText" />
<FieldRef Name="RedFlyoutText" />
<FieldRef Name="OrangeFlyoutText" />
<FieldRef Name="LightBlueFlyoutText" />
<FieldRef Name="BlueFlyoutText" />
<FieldRef Name="AttentionExplanatoryText" />
<FieldRef Name="ExplanatoryText2" />
<FieldRef Name="HeroImage" />
<FieldRef Name="HeroImageCallOut" />
<FieldRef Name="ExpandedSliderImage" />
</ViewFields>
//嗯我以爲我應該使用類似這樣的foreach循環? foreach(myItems中的ExpandedHomeSlider字段) myItems [「ExplanatoryText」] = field.ExplanatoryText; } – Fawn
我同意你的意思,但沒有辦法用foreach循環而不是linq語句來做到這一點嗎? @Servy – Fawn
@Fawn當然有一些解決方案可以使用'foreach'循環。你提供的內容不會做你想做的事情,但如果你真的想要明確地寫一個'foreach'循環,你可以寫一個解決方案。在這裏我沒有看到有這樣的理由。它當然不會改善任何代碼。 – Servy