Tuesday, April 14, 2015

class does not contain a property with the name

Values in repeater are not displaying either via <%#Eval("Display") %>or <%#DataBinder.Eval(Container.DataItem, "Display")%>. Following is the class schema.


public class SwitchUser
{
    public string EmailId;
    public string Password;
    public string Display;

    public SwitchUser()
    {
    }

    public SwitchUser(string emailId, string password, string display)
    {
        EmailId = emailId;
        Password = password;
        Display = display;
    }

}
This is due to following public properties of class:
    public string EmailId;
    public string Password;
    public string Display;

Currently these are fields but not properties. Add getter and setter to these fields to make them properties. Following is the method to create properties.
    public string EmailId{ get; set; }
    public string Password{ get; set; }
    public string Display { get; set; }

This will resolve the error.