I have this code I want to bind data to grid view without using properties .
public class UserTerritory
{
public string TerrId;
public string TerrName;
public string AccAccessLevel;
public UserTerritory(string _TerrId, string _TerrName, string _AccAccessLevel)
{
this.TerrId = _TerrId;
this.TerrName = _TerrName;
this.AccAccessLevel= _AccAccessLevel;
}
}
protected void Page_Load(object sender, EventArgs e)
{
List<UserTerritory> ut = new List<UserTerritory>();
ut.Add(new UserTerritory("1", "x", "a"));
ut.Add(new UserTerritory("2", "y", "b"));
ut.Add(new UserTerritory("3", "z", "c"));
grdUserTerr.DataSource = ut;
grdUserTerr.DataBind();
}
When I execute the above code I get following Httpexception ” The data source for GridView with id ‘grdUserTerr’ did not have any properties or attributes from which to generate columns. Ensure that your data source has content.”
Can Somebody tell me what wrong I am doing ?
Thanks for your reply
The problem is that databinding uses DataBinder.Eval (or just Eval ) behind the scenes and it
looks only for properties. They aren’t exactly the same as public members (fields). Properties are closer to methods than fields are.
So why don’t you just use properties like this?