Dynamically Creating a CustomList, With Lookup field
private void setAlist()
{
try
{
SPWeb web = site.AllWebs[ConfigurationManager.AppSettings["WEB_SITE"].ToString()];
web.AllowUnsafeUpdates = true;
SPList oldList = web.Lists["Subject"];
System.Guid oldGuid = oldList.ID;
System.Guid id = web.Lists.Add("ChanakaNEW", "", SPListTemplateType.GenericList);
SPList MCQList = web.Lists["ChanakaNEW"];
System.Guid iddd = MCQList.ID;
web.Lists[iddd].Fields.Add("StudentID", SPFieldType.Text, true);
web.Lists[iddd].Fields.Add("Marks", SPFieldType.Number, false);
web.Lists[iddd].Fields.AddLookup("Try",oldGuid,false);
//web.Lists[iddd].Fields.Add("Trying", oldGuid, false);
foreach (ListItem listOf in listNames)
{
SPList newList = web.Lists["ChanakaNEW"];
SPListItem newListItem = newList.Items.Add();
//if ((!IsExist(name)) && (!name.Equals(string.Empty)))
{
newListItem["StudentID"] = listOf.Text;
newListItem["Marks"] = 3;
newListItem["Try"] = int.Parse(listOf.Value);
newListItem.Update();
}
}
}
catch(Exception ex)
{
Response.Write(ex.Message);
}
}
No comments:
Post a Comment