sharepoint 查阅项

内容类型

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <!-- 父内容类型: 项目 (0x01) -->
  <ContentType ID="0x0100c2917396131641a896d310050623ef03"
               Name="Demo - Employee"
               Group="自定义内容类型"
               Description="我的内容类型"
               Inherits="TRUE"
               Version="0">
    <FieldRefs>
      <FieldRef ID="{0A27A629-CB34-4B6D-A68F-9873EAC77CA5}" Name="EmployeeName"/>
      <FieldRef ID="{13E113B0-4E72-4E61-99FB-3E66C671D636}" Name="Sex"/>
      <FieldRef ID="{A7F0556E-FCBF-4698-AC6B-EBE6E91C5CE5}" Name ="Age"/>
      <FieldRef ID="{250E89A0-73D4-44C8-8310-4E152BA848A8}" Name ="Department"/>
    </FieldRefs>
    <XmlDocuments>
      <XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">
        <FormUrls xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">
          <New>_layouts/Demo/EmployeeAdd.aspx</New>
        </FormUrls>
      </XmlDocument>
    </XmlDocuments>
  </ContentType>
  <Field  ID="{0A27A629-CB34-4B6D-A68F-9873EAC77CA5}"
            Name="EmployeeName"
            DisplayName="用户名"
            Type="Text"
            SourceID="http://schemas.microsoft.com/sharepoint/v3"
            Required="TRUE"
            StaticName="EmployeeName"/>
  <Field ID="{13E113B0-4E72-4E61-99FB-3E66C671D636}"
         Name="Sex"
         DisplayName="性别"
         Type="Text"
         SourceID="http://schemas.microsoft.com/sharepoint/v3"
         Required="TRUE"
         StaticName="Sex"/>
  <Field ID="{A7F0556E-FCBF-4698-AC6B-EBE6E91C5CE5}"
         Name="Age"
         DisplayName="年龄"
         Type="Text"
         SourceID="http://schemas.microsoft.com/sharepoint/v3"
         Required="TRUE"
         StaticName="Age"/>
  <Field ID="{250E89A0-73D4-44C8-8310-4E152BA848A8}"
         Name="Department"
         DisplayName="部门"
         Type="Lookup"
         ShowField="Department"
         List="Lists/DepartmentList"
         SourceID="http://schemas.microsoft.com/sharepoint/v3"
         Required="TRUE"
         StaticName="Department"/>
</Elements>

绑定部门信息

protected void BindDropDownList()
        {
            try
            {

                SPList tempList = SPContext.Current.Web.Lists["DepartmentList"];
                foreach (SPListItem item in tempList.Items)
                {
                    string strTitle = item.Fields.GetFieldByInternalName("DepartmentName").GetFieldValueAsText(item["DepartmentName"]);
                    if (String.IsNullOrEmpty(strTitle))
                    {
                        continue;
                    }
                    this.ddlstDepartment.Items.Add(new System.Web.UI.WebControls.ListItem(strTitle, item.ID.ToString()));
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }

给查阅项赋值

protected void bt_addSubmit_Click(object sender, EventArgs e)
        {
            if (!CheckInput())
                return;
            SPList list = SPContext.Current.Web.Lists["EmployeeList"];
            if (list != null)
            {
                SPListItem item = list.Items.Add();
                if (item != null)
                {
                    item["Title"] = TextBox1.Text.Trim();
                    string name = txtName.Text.Trim();
                    if (name != "")
                    {
                        item["EmployeeName"] = name;
                    }
                    string sex = txtSex.Text.Trim();
                    if (sex != "")
                        item["Sex"] = sex;

                    string age = txtAge.Text.Trim();
                    if (age != "")
                        item["Age"] = age;
                    SPFieldLookupValue lookupValue = new SPFieldLookupValue(int.Parse(this.ddlstDepartment.SelectedValue), this.ddlstDepartment.SelectedItem.Text);
                    item["Department"] = lookupValue;
                }
                item.Update();
            }
            ClosePage(li_pagestring);
        }

原文地址:https://www.cnblogs.com/GreenGrass/p/3056524.html