Sharepoint Webpart 自定义属性

 

  

namespace Webpart.Staffing.ViewAll

{

    [ToolboxItemAttribute(false)]

    public partial class ViewAll : WebPart

    {

        public ViewAll()

        {

        }



        private string _listName;

        [Personalizable(true)]

        [WebBrowsable(true)]

        [Category("Customize")]

        [WebDisplayName("List Name")]

        public string ListName

        {

            set { _listName = value; }

            get { return _listName; }

        }



        private DataTable GetItems()

        {

            SPListItemCollection collJD = null;

            SPSecurity.RunWithElevatedPrivileges(delegate()

            {

                using (SPSite site = new SPSite(SPContext.Current.Web.Url))

                {

                    using (SPWeb web = site.OpenWeb())

                    {

                        SPList list = web.Lists.TryGetList(string.IsNullOrEmpty(_listName) ? HRConstant.listJDReferral : _listName);

                        SPQuery query = new SPQuery();

                        //query.Query=string.Format("<Where><And><Contains><FieldRef Name=\"Title\" /><Value Type=\"Text\">{0}</Value></Contains><And><Eq><FieldRef Name=\"Job_Location\" /><Value Type=\"Choice\">{1}</Value></Eq><And><Eq><FieldRef Name=\"Level\" /><Value Type=\"Choice\">{2}</Value></Eq><Contains><FieldRef Name=\"Job_Department\" /><Value Type=\"Text\">{3}</Value></Contains></And></And></And></Where>",positionTitle,location,positionLevel,department);

                        query.Query = string.Format("<Where><Eq><FieldRef Name=\"Status\" /><Value Type=\"Choice\">Open</Value></Eq></Where>");

                        query.ViewFields = "<FieldRef Name=\"Level\" /><FieldRef Name=\"Job_Location\" /><FieldRef Name=\"Title\" /><FieldRef Name=\"Job_Department\" />";

                        collJD = list.GetItems(query);

                    }



                }

            });

        }

    }

}    

 

你可能感兴趣的:(SharePoint)