我需要的是向Visual Web Part添加一个脚本,通过单击按钮,将在文本框中显示具有相同标题的ListItem。 作为基础,我使用了这个脚本:
<script type="text/javascript">
ExecuteOrDelayUntilScriptLoaded(MainFunction, "sp.js");
var objContext = null;
var objWeb = null
var objList = null;
var objItem = null;
function MainFunction() {
objContext = new SP.ClientContext.get_current();
objWeb = objContext.get_web();
objList = objWeb.get_lists().getByTitle("Product");
objContext.load(objList);
objContext.executeQueryAsync(Function.createDelegate(this, this.onSuccess), Function.createDelegate(this, this.onFail));
}
function onSuccess(sender, args) {
alert('Item Count: ' + objList.get_itemCount());
}
function onFail(sender, args) {
alert('Some error has occured.');
}
</script>
我的问题是:“有没有办法以某种方式改进这个脚本来实现我的目标?”
答案 0 :(得分:0)
这是:
SPWeb web = SPContext.Current.Web;
SPList list = web.Lists["CustomList"];
SPQuery qry = new SPQuery();
qry.Query = @" <Where><Eq> <FieldRef Name='Title' /><Value Type='Text'>" + TextTitle.Text + "</Value></Eq></Where>";
SPListItemCollection result = list.GetItems(qry);
TextBoxCheck.Text = result.Count.ToString() + " matches has been found";