locked
How to customise spfield of type singlelinetext and add to survey list RRS feed

  • Question

  • Hi All,

    I created a survey in share point and trying to add  fields into it programatically using a GUI.Now the problem is in the field type customization.I want to set  default text to a singlelinetext type field.How can I do this?

    I tried this

    SPField spfldmutiline= new SPField(objSurvey.Fields, SPFieldType.Text.ToString(), strQuestion);
    objSurvey.Fields.Add(spfldmutiline);
    objSurvey.Update();

    PFieldText spfldtxt = (SPFieldText)objSurvey.Fields[strQuestion];
    spfldtxt.DefaultValue = txtdefault.Text;
    objSurvey.Fields.Add(spfldtxt);
    objSurvey.Update();

    But as you see ,it creates 2 text boxes.

    How can I add a field of type singlelinetext and customize it?

    Help is appreciable.


    Celesta Joseph


    Thursday, October 11, 2012 11:11 AM

Answers

  • Hi;

    Try below code (this is similar code as i have posted in your another thread)

    foreach (SPField field in objSurvey.Fields)
    {
    if (field.Title == "Put your column name here..it is case sensitive so be careful")
    {
    field.field.DefaultValue = "New Text Field";
    field.Update();
    break;
    }
    }
    objSurvey.Update(); 

    Hope it could help


    Cheers, Hemendra-MCTS "Yesterday is just a memory,Tomorrow we may never see"

    Friday, October 12, 2012 11:54 AM
    Moderator

All replies

  • Hi;

    Try below code (this is similar code as i have posted in your another thread)

    foreach (SPField field in objSurvey.Fields)
    {
    if (field.Title == "Put your column name here..it is case sensitive so be careful")
    {
    field.field.DefaultValue = "New Text Field";
    field.Update();
    break;
    }
    }
    objSurvey.Update(); 

    Hope it could help


    Cheers, Hemendra-MCTS "Yesterday is just a memory,Tomorrow we may never see"

    Friday, October 12, 2012 11:54 AM
    Moderator
  • Hi,

    Have you resolved you problem? If yes then provide your solution so other can take benefit of that and if above post help you to resolve your problem then mark it as answer.


    Hemendra: "Yesterday is just a memory,Tomorrow we may never see"

    Whenever you see a reply and if you think is helpful, click "Alternate TextVote As Helpful"! And whenever you see a reply being an answer to the question of the thread, click "Alternate TextMark As Answer

    Friday, November 16, 2012 10:08 AM
    Moderator