I have an ASP.NET Gridview control that allows you to select an employee.
The employee entity has a navigation property for group entity.
I have an ASP.NET ListView control that displays all the groups that an employee is in.
The SelectedIndexChanged function of the GridView looks like this
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
DAL.SafetyContext sc = new DAL.SafetyContext();
long empid = (long)GridView1.SelectedDataKey.Value;
DAL.Employee emp = sc.Employees.Where(x => x.EID == empid).FirstOrDefault();
ListView1.DataSource = emp.Groups;
ListView1.DataBind();
}
The problem is that I can't <%#Eval("Name") %> in the item template of the ListView because there is no data bound to control when the page loads.
Is there a way around this?