Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
G

Georby

@Georby
About
Posts
1
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Add values to a list contains a Lookup Field
    G Georby

    I have a list named "Designation" that contains a Designation Code and Designation Name. I have another list named "Employee" that contains Employee Name and Designation Name (as a Lookup Field). I am able to insert values to "Employee" list using the following code. protected void AddEmp(object sender, EventArgs e) { string emp_name = txtEmployeeName.Text; string emp_designation = ddlDesignation.SelectedValue; using (SPSite site = new SPSite("My Site")) { using (SPWeb web = site.OpenWeb()) { SPSecurity.RunWithElevatedPrivileges(delegate() { web.AllowUnsafeUpdates = true; SPList splist_employees = web.Lists["Employee"]; SPList splist_designations = web.Lists["Designations"]; SPListItemCollection splc_items = splist_employees.Items; SPListItem spli_item = splc_items.Add(); SPFieldLookup lookup = splist_employees.Fields["Designated"] as SPFieldLookup; string fieldName = lookup.LookupField; spli_item["Employee Name"] = emp_name; spli_item[fieldName] = GetLookFieldIDS(emp_designation, splist_designations); spli_item.Update(); }); } } } public static string GetLookFieldIDS(string lookupValues, SPList lookupSourceList) { string id = string.Empty; SPFieldLookupValueCollection lookupIds = new SPFieldLookupValueCollection(); SPQuery query = new Microsoft.SharePoint.SPQuery(); query.Query = ""+lookupValues + ""; SPListItemCollection listItems = lookupSourceList.GetItems(query); foreach (Microsoft.SharePoint.SPListItem item in listItems) { id = item.ID.ToString(); } return id; } Here I have given the field name as 'Designation' inside the query. But, I want to find the field name based on the value given from the user end instead of hard-coding the field name as 'Designation'. Any help is greatly appreciated. Thanks in advance.

    SharePoint sharepoint database help announcement
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups