1

Actually am fetching data from list to my drop down list(ddlseverity).

I want to get selected value from drop-down and display the value in choice filed in SharePoint list. after click submit button selected item will not be inserted into choice filed How can I achieve this?

SPFieldChoice fieldChoice = (SPFieldChoice)list.Fields.GetFieldByInternalName
                        (itemToAdd.Fields.Add(ddlpriority.Text, SPFieldType.Choice, true));
                        string[] types = { ddlpriority.Text };
                        fieldChoice.Choices.AddRange(types);
                        fieldChoice.Update();
8
  • fetching data from list to drop down(ddlseverity) working fine.
    – chakri
    Commented Sep 24, 2015 at 8:05
  • after click submit button selected item will not be inserted into choice filed
    – chakri
    Commented Sep 24, 2015 at 8:07
  • SPFieldChoice fieldChoice = (SPFieldChoice)list.Fields.GetFieldByInternalName (itemToAdd.Fields.Add(ddlpriority.Text, SPFieldType.Choice, true)); string[] types = { ddlpriority.Text }; fieldChoice.Choices.AddRange(types); fieldChoice.Update();
    – chakri
    Commented Sep 24, 2015 at 8:07
  • You want to create a new Choice column every time or update an existing column Commented Sep 24, 2015 at 8:17
  • then you have to update the list also. did you do that? Commented Sep 24, 2015 at 8:36

1 Answer 1

2

Based on your comment, I got that you wish to create a new column every time. So try something like following

 list.Fields.Add("Your Field Name", SPFieldType.Choice, false);
 SPFieldChoice col = (SPFieldChoice) list.Fields["Your Field Name"];

 col.Choices.Add("option 1");
 col.Choices.Add("option 2");
 col.DefaultValue = "option 1"; 

 col.update(); 
 list.update();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.