Quantcast
Channel: Forum CRM Development
Viewing all articles
Browse latest Browse all 1000

Can't Get OptionSetValue using Linq C#

$
0
0

Ok. What I'm trying to do is simple. I want to display the contacts in a gridview. I've written code that gets me close... but all picklist fields appear in the gridview as "Microsoft.Xrm.Sdk.OptionSetValue". I need it to show the actual string. I've read that using "FormattedValues" will get me what I need, but it errors out. I get "The given key was not present in the dictionary."

The following code works:

            var SoarContacts =
                (
                    from c in context.ContactSet
                    where c.FullName.Contains(NameTextBox.Text)
                    where c.StatusCode.Value == 1
                    orderby c.FullName descending
                    select new
                    {
                        ContactID = c.ContactId,
                        FullName = c.FullName,
                        Gender = c.GenderCode,
                        DOB = c.BirthDate,
                        Status = c.StatusCode
                    }
                );
            DataTable dt = new DataTable();
            dt.Columns.Add("ContactID", typeof(string));
            dt.Columns.Add("FullName", typeof(string));
            dt.Columns.Add("Gender", typeof(string));
            dt.Columns.Add("DOB", typeof(DateTime));
            dt.Columns.Add("Status", typeof(string));

            foreach (var c in SoarContacts)
            {
                dt.Rows.Add(c.ContactID, c.FullName, c.Gender, c.DOB, c.Status);
            }

            RecordCount.Text = dt.Rows.Count.ToString() + " Contacts";
            ResultsGridView.DataSource = dt;
            ResultsGridView.DataBind();
But I need to see the actual Gender string and status string. Changing "Gender = c.GenderCode" to "Gender = c.FormattedValues["gendercode"] does not work. How do I manipulate the code that I have to include the gender and status?


Viewing all articles
Browse latest Browse all 1000


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>