0

我需要向 Visual Web 部件添加一个脚本,女巫将通过单击按钮在文本框中显示具有相同标题的 ListItems。作为基础,我使用了这个脚本:

<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>

我的问题是:“有没有办法以某种方式改进这个脚本来实现我的目标?”

4

1 回答 1

0

Here it is:

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";  
于 2013-07-05T09:29:31.340 回答