ListViewWebPart 如何 Connection 其它的Web Part?

DJ2008 2009-07-28 03:19:53

我希望能做一个新的Web Part,用其来作为一个ListViewWebPart (如Document Library)的一个导航控件,可直接控制此Document Library 跳至第一页/前一页/下一页/最后一页等处理。

不知有没有朋友什么提供什么解决方法?

ListViewWebPart 本身提供了Provide Row To / Provide View Data To / Get Sort/Filter From 三种和其它Web Part 进行Connection 的方式,但如何使用呢?能否提供一个例子或代码?

谢谢。
...全文
134 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
DJ2008 2009-12-08
  • 打赏
  • 举报
回复
明白LS 的意思,是一个例子,如何使用 Filter,结贴了,太久了
HugoWong 2009-08-26
  • 打赏
  • 举报
回复
public class DataBoundHeadlinesFilterConsumerWebPart : aspnetwebparts.WebPart
{

public class Headline
{
private string title;
private string region;

public Headline(string Title, string Region)
{

this.title = Title;
this.region = Region;

}
public string Title
{
get
{
return this.title;
}
set
{
this.title = value;
}
}

public string Region
{
get
{
return this.region;
}
set
{
this.Region = value;
}
}



}

List<wsswebparts.IFilterValues> providers = new List<wsswebparts.IFilterValues>();
List<Headline> headlines;

DataGrid DataListHeadlines;

protected override void CreateChildControls()
{
DataListHeadlines = new DataGrid();

headlines = new List<Headline>();

headlines.Add(new Headline("This week in Redmond", "Redmond"));
headlines.Add(new Headline("Traffic in Redmond", "Redmond"));
headlines.Add(new Headline("Sports highlights in Redmond", "Redmond"));
headlines.Add(new Headline("Bitter cold, wind to follow today's snow", "Seattle"));
headlines.Add(new Headline("This week in Seattle", "Seattle"));
headlines.Add(new Headline("Sports News in US", "US"));
headlines.Add(new Headline("This week in the US", "US"));
headlines.Add(new Headline("This week in the world", "World"));
headlines.Add(new Headline("Last week sports highlights", "World"));


DataListHeadlines.ID = "list1";
Controls.Add(DataListHeadlines);

base.CreateChildControls();
}


[aspnetwebparts.ConnectionConsumer("Headlines Filter", "IFilterValues", AllowsMultipleConnections = true)]
public void SetConnectionInterface(wsswebparts.IFilterValues provider)
{
if (provider != null)
{
this.providers.Add(provider);

List<wsswebparts.ConsumerParameter> l = new List<wsswebparts.ConsumerParameter>();
l.Add(new wsswebparts.ConsumerParameter("Region",
wsswebparts.ConsumerParameterCapabilities.SupportsMultipleValues | wsswebparts.ConsumerParameterCapabilities.SupportsAllValue));

provider.SetConsumerParameters(new ReadOnlyCollection<wsswebparts.ConsumerParameter>(l));
}
}

protected override void OnPreRender(EventArgs e)
{
this.EnsureChildControls();

// The filtering logic is to perform a union of all of the filters
// (a logical OR).
// If we didn't get any filter providers or if any of the filters
// send the "All" value (i.e. if provider.ParameterValues == null)
// then we don't need to filter and we can just send back all of
// the headlines.

List<Headline> filteredHeadlines = null;

bool shouldFilter = true;
if (this.providers.Count == 0)
{
shouldFilter = false;
}
else if (this.providers.Count > 0)
{
foreach( wsswebparts.IFilterValues filter in this.providers)
{
if (filter.ParameterValues == null)
{
// Some filter sent "All" - don't bother with the rest
// of the filtering.
shouldFilter = false;
break;
}
}
}


if (!shouldFilter)
{
// the "filtered" headlines are unfiltered.
filteredHeadlines = this.headlines;
}
else
{
// Just fill in the headlines that match the filters.

filteredHeadlines = new List<Headline>();

// Create a lookup from region to a list of headlines which
// correspond to that region.
Dictionary<string, List<Headline>> regionHeadlineMap = new Dictionary<string,List<Headline>>();
foreach (Headline headline in this.headlines)
{
List<Headline> headlinesForRegion = null;
if (!regionHeadlineMap.TryGetValue(headline.Region, out headlinesForRegion))
{
headlinesForRegion = new List<Headline>();
regionHeadlineMap.Add(headline.Region, headlinesForRegion);
}

headlinesForRegion.Add(headline);
}

foreach (wsswebparts.IFilterValues provider in this.providers)
{

ReadOnlyCollection<String> values = provider.ParameterValues;
if (values != null)
{
foreach (string v in values)
{
if (v == null)
{
// This indicates the "Empty" value, which this
// doesn't apply to headlines, since they all
// have a Region.
}
else
{
List<Headline> matchedHeadlines;
if (regionHeadlineMap.TryGetValue(v, out matchedHeadlines))
{
foreach (Headline matchedHeadline in matchedHeadlines)
{
if (!filteredHeadlines.Contains(matchedHeadline))
{
filteredHeadlines.Add(matchedHeadline);
}
}
}
}
}
}
}
}

// Display the filtered headlines.
DataListHeadlines.DataSource = filteredHeadlines;
DataListHeadlines.DataBind();

base.OnPreRender(e);
}
}
}
HugoWong 2009-08-26
  • 打赏
  • 举报
回复
public class RegionFilterWebPart : aspnetwebparts.WebPart, wsswebparts.ITransformableFilterValues
{
CheckBoxList cblRegionList;
ListItem cbitemRegion;

public virtual bool AllowMultipleValues
{
get
{
return true;
}
}
public virtual bool AllowAllValue
{
get
{
return true;
}
}

public virtual bool AllowEmptyValue
{
get
{
return false;
}
}
public virtual string ParameterName
{
get
{
return "Geography";
}
}

public virtual ReadOnlyCollection<string> ParameterValues
{
get
{
string[] values = this.GetCurrentlySelectedGeographies();
return values == null ?
null :
new ReadOnlyCollection<string>(values);
}
}




protected override void CreateChildControls()
{
cblRegionList = new CheckBoxList();
Controls.Add(cblRegionList);

cbitemRegion = new ListItem();
cbitemRegion.Text = "Seattle";
cblRegionList.Items.Add(cbitemRegion);
cbitemRegion = null;

cbitemRegion = new ListItem();
cbitemRegion.Text = "US";
cblRegionList.Items.Add(cbitemRegion);
cbitemRegion = null;

cbitemRegion = new ListItem();
cbitemRegion.Text = "World";
cblRegionList.Items.Add(cbitemRegion);
cbitemRegion = null;

cbitemRegion = new ListItem();
cbitemRegion.Text = "All";
cblRegionList.Items.Add(cbitemRegion);
cbitemRegion = null;


base.CreateChildControls();
}


[aspnetwebparts.ConnectionProvider("Region Filter", "ITransformableFilterValues", AllowsMultipleConnections = true)]
public wsswebparts.ITransformableFilterValues SetConnectionInterface()
{
return this;
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
}

public string[] GetCurrentlySelectedGeographies()
{
String[] choices = new String[5];
bool anythingSelected = false;

for (int i = 0; i < cblRegionList.Items.Count; i++)
{
//get the selected choices
if (cblRegionList.Items[i].Selected)
{
anythingSelected = true;
if (cblRegionList.Items[i].Text != "All")
{
choices[i] = cblRegionList.Items[i].Text;
}
else
{
choices = null;
return choices;
}
}

}
if (!anythingSelected)
choices = null;

return choices;
}

protected override void RenderContents(HtmlTextWriter output)
{
this.EnsureChildControls();
RenderChildren(output);


}

}
HugoWong 2009-08-26
  • 打赏
  • 举报
回复
public class SimpleFilterConsumerWebPart : aspnetwebparts.WebPart
{

List<wsswebparts.IFilterValues> providers = new List<wsswebparts.IFilterValues>();


protected override void CreateChildControls()
{
base.CreateChildControls();
}


[aspnetwebparts.ConnectionConsumer("Simple Consumer", "IFilterValues", AllowsMultipleConnections = false)]
public void SetConnectionInterface(wsswebparts.IFilterValues provider)
{
this.providers.Add(provider);
if (provider != null)
{
List<wsswebparts.ConsumerParameter> l = new List<wsswebparts.ConsumerParameter>();
l.Add(new wsswebparts.ConsumerParameter("Value", wsswebparts.ConsumerParameterCapabilities.SupportsMultipleValues | wsswebparts.ConsumerParameterCapabilities.SupportsAllValue));
provider.SetConsumerParameters(new ReadOnlyCollection<wsswebparts.ConsumerParameter>(l));
}
}

protected override void RenderContents(HtmlTextWriter output)
{
this.EnsureChildControls();
foreach (wsswebparts.IFilterValues provider in this.providers)
{
if (provider != null)
{
string prop = provider.ParameterName;
ReadOnlyCollection<String> values = provider.ParameterValues;

if (prop != null && values != null)
{
output.Write("<div>" + SPEncode.HtmlEncode(prop) + ":</div>");
foreach (string v in values)
{
if (v == null)
{
output.Write("<div>  <i>"(empty)"/null</i></div>");
}
else if (v.Length == 0)
{
output.Write("<div>  <i>empty string</i></div>");
}
else
{
output.Write("<div>  " +v + "</div>");
}
}
}
else
{
output.Write("<div>No filter specified (all).</div>");
}
}
else
{
output.Write("<div>Not connected.</div>");
}

output.Write("<hr>");
}
}

}
guozi612 2009-08-19
  • 打赏
  • 举报
回复
没明白你的意思,看你说的好像就是分页啊,干嘛要2个Webpart的connection
DJ2008 2009-08-18
  • 打赏
  • 举报
回复
没人,是不是要到其它更专业的BBS上才行呀
DJ2008 2009-08-13
  • 打赏
  • 举报
回复
谢谢LS,继续UP
yuanyuyuyu 2009-07-31
  • 打赏
  • 举报
回复
帮忙
DJ2008 2009-07-30
  • 打赏
  • 举报
回复
up
DJ2008 2009-07-28
  • 打赏
  • 举报
回复
up

3,242

社区成员

发帖
与我相关
我的任务
社区描述
企业开发 SharePoint
社区管理员
  • SharePoint社区
  • 霖雨
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧