'System.Collections.Generic.List<string>' does not contain adefinition for 'Distinct'

J

jc

Sharepoint development.



I've added this inline code block to Sharepoint page.

I know the Web front end where it's running has .NET 3.0

<script runat="server">
protected void Page_PreRender(object sender, EventArgs e)
{
SPWeb web = SPContext.Current.Web;
SPList list = web.Lists["Facilities"];
SPField field = list.Fields["Title"];
List<string> Titles = new List<string>();
foreach(SPListItem spli in list.Items)
{
Titles.Add(spli[field.Id].ToString());
}
Titles.Sort();
Titles.Distinct().ToList().ForEach(delegate(string code)
{
Facilities.Items.Add(new ListItem(code));
});
}
</script>

I'm getting this error:

'System.Collections.Generic.List<string>' does not contain a
definition for 'Distinct'


Thanks for any help or information.
 
A

Arne Vajhøj

jc said:
I've added this inline code block to Sharepoint page.

I know the Web front end where it's running has .NET 3.0

<script runat="server">
protected void Page_PreRender(object sender, EventArgs e)
{
SPWeb web = SPContext.Current.Web;
SPList list = web.Lists["Facilities"];
SPField field = list.Fields["Title"];
List<string> Titles = new List<string>();
foreach(SPListItem spli in list.Items)
{
Titles.Add(spli[field.Id].ToString());
}
Titles.Sort();
Titles.Distinct().ToList().ForEach(delegate(string code)
{
Facilities.Items.Add(new ListItem(code));
});
}
</script>

I'm getting this error:

'System.Collections.Generic.List<string>' does not contain a
definition for 'Distinct'

You will need .NET 3.5 and you will need to tell your web app
to use 3.5 when compiling.

You can add something like:

<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
compilerOptions="/warnaserror-" warningLevel="4"
type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v3.5"/>
</compiler>
<compiler language="vb;vbs;visualbasic;vbscript"
extension=".vb" compilerOptions="/optioninfer+"
type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v3.5"/>
</compiler>
</compilers>
</system.codedom>

to web.config.

Arne
 
J

jc

We will eventually really want to do this, but we need to test .net
3.5 on a test farm first...

I was going to code a work around, but have an issue where I can't
even find my dropdownlist from my code block.. and SPD is not easy
for troubleshooting.

I've tried OnInit, OnLoad and OnPrerender.


protected void Page_OnInit(object sender, EventArgs e)
{
SPWeb web = SPContext.Current.Web;
SPList list = web.Lists["Facilities"];
SPField field = list.Fields["Title"];
List<string> Titles = new List<string>();
foreach(SPListItem spli in list.Items)
{
DropDownList fddl = (DropDownList)this.Page.FindControl
("FacilityDDL");
fddl.Items.Add("x");

// if (!fddl.Items.Contains(spli[field.Id].ToString()))
//if (fddl.Items.IndexOf(fddl.Items.FindByValue(spli
[field.Id].ToString())) =-1)
//{
//response.write("x");
// fddl.Items.Add(spli[field.Id].ToString());
//}
}
}
</script>

my asp.net control is inside:

<WebPartPages:DataFormWebPart


<asp:DropDownList runat="server" id="FacilityDDL"
DataTextField="Title" DataValueField="Title" /></td>

Am I missing something here?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top