问题描述
在自定义Web部件中,我正在使用"SharePoint:ListViewByQuery"控制as-
In a custom web part, i am using a "SharePoint:ListViewByQuery" control as-
< SharePoint:ListViewByQuery ID =" ListViewByQueryControl" runat =服务器" />
<SharePoint:ListViewByQuery ID="ListViewByQueryControl" runat="server" />
和使用查询as-
.cs:
SPList oList = web.Lists.TryGetList("MyRecord");
SPList oList = web.Lists.TryGetList("MyRecord");
ListViewByQueryControl.List = oList;
ListViewByQueryControl.List = oList;
SPQuery查询=新的SPQuery(oList.Views [" DataSheetViewName"]]);
SPQuery query = new SPQuery(oList.Views["DataSheetViewName"]);
query.Query =< Where>< Eq>< FieldRef Name ='Project_ID'/>< Value Type ='Lookup'>" + projectId +</Value></Eq></Where>"
query.Query = "<Where><Eq><FieldRef Name='Project_ID' /><Value Type='Lookup'>" + projectId + "</Value></Eq></Where>"
ListViewByQueryControl.Query =查询;
ListViewByQueryControl.Query = query;
使用此功能,我可以绑定数据,但我的页面上没有DataSheetView.
using this i am able to bind the data but i am not getting the DataSheetView on my page.
推荐答案
请为查询设置ViewField,如下所示:
Please set ViewField for the query like below:
protected void Page_Load(object sender, EventArgs e)
{
SPSite site = new SPSite("http://sp/sites/calevent/");
SPWeb web = site.OpenWeb();
SPList list = web.Lists["Custom1"];
SPView view = list.Views["All Items"];
SPQuery query = new SPQuery(view);
query.ViewFields = "<FieldRef Name='Title'/>";
query.Query = "<Where>" +
"<Eq>" +
"<FieldRef Name='Title' />" +
"<Value Type='Text'>Jerry</Value>" +
"</Eq>" +
"</Where>";
SPListViewByQuery1.List = list;
SPListViewByQuery1.Query = query;
}
结果:
更多信息:
http://snahta.blogspot.sg/2008/09/using-listviewbyquery-control-in-your.html
谢谢
这篇关于如何在SharePoint2010中将DataSheetView与自定义Web部件一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!