<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="Match_ID" DataSourceID="SqlDataSource4">
<Columns>
<asp:BoundField DataField="Team_name" HeaderText="Team_name" SortExpression="Team_name" />
<asp:BoundField DataField="Match_ID" HeaderText="Match_ID" InsertVisible="False" ReadOnly="True" SortExpression="Match_ID" />
<asp:BoundField DataField="Home_team_ID" HeaderText="Home_team_ID" SortExpression="Home_team_ID" />
<asp:BoundField DataField="Away_team_ID" HeaderText="Away_team_ID" SortExpression="Away_team_ID" />
<asp:BoundField DataField="Home_team_score" HeaderText="Home_team_score" SortExpression="Home_team_score" />
<asp:BoundField DataField="Away_team_score" HeaderText="Away_team_score" SortExpression="Away_team_score" />
<asp:BoundField DataField="Game_date" HeaderText="Game_date" SortExpression="Game_date" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:SportsData2ConnectionString %>" SelectCommand="SELECT Team.Team_name, MatchStatistics.Match_ID, MatchStatistics.Home_team_ID, MatchStatistics.Away_team_ID, MatchStatistics.Home_team_score, MatchStatistics.Away_team_score, MatchStatistics.Game_date FROM MatchStatistics INNER JOIN Team ON MatchStatistics.Home_team_ID = Team.Team_ID AND MatchStatistics.Away_team_ID = Team.Team_ID ORDER BY MatchStatistics.Game_date DESC"></asp:SqlDataSource>
I want to create a GridView displaying all records inside MatchStatistics. To do so I need to gather Team_name
from the Team
table. However, even when MatchStatistics
has data the select statement doesn't work. What's wrong with it?
My intended GridView should be all of the contents of MatchStatistics
with Home and away Team IDs replaced with their Team_names
. Similar to below but with dropdownlists in place of home and away team ID.