Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
|
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 5th, 2012, 05:20 PM
Registered User
 
Join Date: May 2012
Posts: 6
Thanks: 2
Thanked 0 Times in 0 Posts
Default Gridview or ListView Editing - showing data for reference from other tables

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.
 
Old July 6th, 2012, 11:02 AM
Registered User
 
Join Date: May 2012
Posts: 6
Thanks: 2
Thanked 0 Times in 0 Posts
Default

I managed to find a solution to this.

I added a template into my gridview, linking it to another linqdatasource

<asp:TemplateField HeaderText="Home">
<ItemTemplate>
<asp:DropDownList ID="HomeDropDownList" runat="server"
DataSourceID="TableLinqDataSource1" DataTextField="ClubShortName"
DataValueField="LeagueTeamId"
Text='<%# Bind("HomeTeam") %>' />
</ItemTemplate>
</asp:TemplateField>


It's not ideal as I have a drop-down box even before I hit the edit button, so any ideas on how I can make it a just show the name unless I go into edit mode?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Listview...editing/updating/inserting layout RichardL1969 ASP.NET 4 General Discussion 3 July 3rd, 2012 07:13 AM
Data Binding - Editing GridView Row Data desk_star BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 7 December 30th, 2007 11:07 AM
how can i do in place editing in gridview barunvicky BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 1 September 7th, 2007 10:55 AM
Data Binding from many Tables to Gridview khoder ASP.NET 2.0 Professional 1 February 19th, 2007 10:22 AM
Editing all GridView rows Abbas C# 2005 0 November 29th, 2006 03:52 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.