SharePoint 201 ListViewByQuery Control 应用
学习MSDN视频教程,没有源代码,自己按照视频上的demo测试的
地址:http://msdn.microsoft.com/zh-cn/sharepoint/ee513147.aspx
[ToolboxItemAttribute(false)]
public class Bonnevlie_StandardWP : WebPart
{
ListViewByQuery MyCustomView;
protected override void CreateChildControls()
{
SPWeb thisWeb = null;
thisWeb = SPContext.Current.Web;
DateTimeControl filterDate = new DateTimeControl();
filterDate.DateOnly = true;
filterDate.AutoPostBack = true;
filterDate.SelectedDate = DateTime.Today;
filterDate.DateChanged += new EventHandler(filterDate_DateChanged);
this.Controls.Add(filterDate);
this.Controls.Add(new LiteralControl("<br/>"));
MyCustomView = new ListViewByQuery();
MyCustomView.List = thisWeb.Lists["任务"];
SPQuery query = new SPQuery(MyCustomView.List.DefaultView);
query.ViewFields = "<FieldRef Name='Title'/><FieldRef Name='DueDate'/>";
query.Query = "<Where><Leq><FieldRef Name='DueDate'/>"
+ "<Value Type='DateTime'>"
+ SPUtility.CreateISO8601DateTimeFromSystemDateTime(filterDate.SelectedDate)
+ "</Value></Leq></Where>";
MyCustomView.Query = query;
this.Controls.Add(MyCustomView);
}
void filterDate_DateChanged(object sender, EventArgs e)
{
//throw new NotImplementedException();
DateTimeControl filterDate = (DateTimeControl)sender;
SPQuery query = new SPQuery(MyCustomView.List.DefaultView);
query.ViewFields = "<FieldRef Name='Title'/><FieldRef Name='DueDate'/>";
query.Query = "<Where><Leq><FieldRef Name='DueDate'/>"
+ "<Value Type='DateTime'>"
+ SPUtility.CreateISO8601DateTimeFromSystemDateTime(filterDate.SelectedDate)
+ "</Value></Leq></Where>";
MyCustomView.Query = query;
}
}