I have (or will have) an admin page on my website for a ficticious non-league football team, which will allow me to enter all the results each week.
I have a table called fixtures which has columns of...
FixtureId
HomeTeamId
AwayTeamId
WeekId
HomeScore
awayScore
I set this up to be editable using a gridview easy enough, however, because I used Id references for the teams, it isn't too clear who is who in each fixture, e.g. 8 v 4 and 9 v 15 isn't too meaningful.
The team names are stored in a table called teams, which just has a team name and a TeamId for each team.
Is there any way of making a gridview or ListView (or any more suitable control) use the returned HomeTeamId to look up the team name from the teams table, and display that in place instead?
I have actually sort of got this working using Linq
Code:
protected void Page_Load(object sender, EventArgs e)
{
using (aspnetdbEntities1 ent = new aspnetdbEntities1())
{
var fixs = from games in ent.Fixtures
join hteams in ent.Teams on games.HomeTeam equals hteams.TeamId
join ateams in ent.Teams on games.AwayTeam equals ateams.TeamId
orderby hteams.ClubName
select new {games.FixtureId, games.Week, home = hteams.ClubShortName, away = ateams.ClubShortName, games.HomeScore, games.AwayScore };
this.ResultsGridView.DataSource = fixs;
this.ResultsGridView.DataBind();
}
}
but I get an error with that (The GridView 'ResultsGridView' fired event RowEditing which wasn't handled) and I'm wondering if I'm just overcomplicating things.
Likewise, I probably could do it with an SQLDataSource playing around with the SQL, but that feels like working round the problem when I really want to find out how it's meant to be done.
Thanks.