Click here to Skip to main content
15,891,843 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Not clear why following code returns "A valid data source must implement either IListSource or IEnumerable"

public class CGroup<TKey, TValue> 
{
  public TKey Key { get; set; }
  public IEnumerable<TValue> Values { get; set; }
}

//AIT is declared class
var cg = new CGroup<string, AIT>();
cg.Key = "Key Value";
//line below raises error, also tried new List<AIT>();
//Empty list is fine
cg.Values = new List<AIT>(){};
aRepeater.DataSource = cg;
aRepeater.DataBind();


Appreciate any input

What I have tried:

I tried declaring an empty list for cg.Values in different ways but still errors.
Posted
Updated 12-Apr-17 2:52am
Comments
Tomas Takac 6-Apr-17 8:53am    
Try this: aRepeater.DataSource = cg.Values;

it should be
aRepeater.DataSource = cg.Values;

since Values property gives the List which is of type IEnumerable interface
 
Share this answer
 
v2
Comments
RjBFlorida 6-Apr-17 9:01am    
Thanks for response, however it's the line above that errors:
cg.Values = new List<ait>(){};
Karthik_Mahalingam 6-Apr-17 9:05am    
i have checked, it works fine in that line, might be you are missing something

what is the actual value you are assigning to it
CHill60 6-Apr-17 9:16am    
Are you sure you are debugging the right source or the error message is actually as you have stated it. The line of code you are indicating as the error and the error message do not match up. The error message with the line after that makes perfect sense
RjBFlorida 12-Apr-17 8:50am    
Yes, seems like the error message is for the line below it but that's where VS stops and points the error at during debugging.
Karthik_Mahalingam 12-Apr-17 9:12am    
is the issue fixed?
Unfortunately, I couldn't find the solution for this so instead of trying to create an empty datasource with a key value (was hoping the key value would display "empty" in the list), I instead set the datasource to null and used labels to display "empty".
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900