Skip to main content
added 20 characters in body
Source Link
Thomas Mathew
  • 505
  • 2
  • 12
  • 32

I have created a Survey List in MOSS 2007. The field used in the survey is of 'Choice' type. While getting the field value in a custom web part program on another page, the FieldRenderingControl of SPField is throwing an exception.

The code for webpart is :

    SPSite mySite = SPContext.Current.Web.Site;

            SPWeb myWeb = mySite.OpenWeb();

            SPList mylist = myWeb.Lists[surveyname];

            int surveyUserCount = mylist.ItemCount;
        try
         {
            
            if (surveyUserCount > 0)
            {
                foreach (SPListItem item in mylist.Items)
                {

                    foreach (SPField field in item.Fields)
                    {
                        if (field.TypeAsString == "Choice")
                        {
                                                                                        
                            string check = Convert.ToString(field.FieldRenderingControl.ItemFieldValue);
                            if (check != "")
                        }
                   }
                }
             }
           }

The exception thrown is : 'field.FieldRenderingControl.ItemFieldValue' threw an exception of type 'System.InvalidOperationException'
base {System.SystemException} = {"Operation is not valid due to the current state of the object."}

I have created a Survey List in MOSS 2007. The field used in the survey is of 'Choice' type. While getting the field value in a custom web part program, the FieldRenderingControl of SPField is throwing an exception.

The code for webpart is :

    SPSite mySite = SPContext.Current.Web.Site;

            SPWeb myWeb = mySite.OpenWeb();

            SPList mylist = myWeb.Lists[surveyname];

            int surveyUserCount = mylist.ItemCount;
        try
         {
            
            if (surveyUserCount > 0)
            {
                foreach (SPListItem item in mylist.Items)
                {

                    foreach (SPField field in item.Fields)
                    {
                        if (field.TypeAsString == "Choice")
                        {
                                                                                        
                            string check = Convert.ToString(field.FieldRenderingControl.ItemFieldValue);
                            if (check != "")
                        }
                   }
                }
             }
           }

The exception thrown is : 'field.FieldRenderingControl.ItemFieldValue' threw an exception of type 'System.InvalidOperationException'
base {System.SystemException} = {"Operation is not valid due to the current state of the object."}

I have created a Survey List in MOSS 2007. The field used in the survey is of 'Choice' type. While getting the field value in a custom web part program on another page, the FieldRenderingControl of SPField is throwing an exception.

The code for webpart is :

    SPSite mySite = SPContext.Current.Web.Site;

            SPWeb myWeb = mySite.OpenWeb();

            SPList mylist = myWeb.Lists[surveyname];

            int surveyUserCount = mylist.ItemCount;
        try
         {
            
            if (surveyUserCount > 0)
            {
                foreach (SPListItem item in mylist.Items)
                {

                    foreach (SPField field in item.Fields)
                    {
                        if (field.TypeAsString == "Choice")
                        {
                                                                                        
                            string check = Convert.ToString(field.FieldRenderingControl.ItemFieldValue);
                            if (check != "")
                        }
                   }
                }
             }
           }

The exception thrown is : 'field.FieldRenderingControl.ItemFieldValue' threw an exception of type 'System.InvalidOperationException'
base {System.SystemException} = {"Operation is not valid due to the current state of the object."}

Source Link
Thomas Mathew
  • 505
  • 2
  • 12
  • 32

FieldRenderingControl of SPField throws an exception for Survey List

I have created a Survey List in MOSS 2007. The field used in the survey is of 'Choice' type. While getting the field value in a custom web part program, the FieldRenderingControl of SPField is throwing an exception.

The code for webpart is :

    SPSite mySite = SPContext.Current.Web.Site;

            SPWeb myWeb = mySite.OpenWeb();

            SPList mylist = myWeb.Lists[surveyname];

            int surveyUserCount = mylist.ItemCount;
        try
         {
            
            if (surveyUserCount > 0)
            {
                foreach (SPListItem item in mylist.Items)
                {

                    foreach (SPField field in item.Fields)
                    {
                        if (field.TypeAsString == "Choice")
                        {
                                                                                        
                            string check = Convert.ToString(field.FieldRenderingControl.ItemFieldValue);
                            if (check != "")
                        }
                   }
                }
             }
           }

The exception thrown is : 'field.FieldRenderingControl.ItemFieldValue' threw an exception of type 'System.InvalidOperationException'
base {System.SystemException} = {"Operation is not valid due to the current state of the object."}