新手在这里。
我正在使用Visual Studio 2015社区。在NFL Pickem游戏的C#Web Forms应用程序上工作。我有一个Game Edit屏幕,它列出了Games表中的NFL游戏,我想允许从下拉列表中编辑Winning Team字段。下拉列表绑定到Teams表,该表是Games表中的外键。我正在使用Matt Dotson的RealWorldGrids中的BulkEditGridView控件和SQL数据源。
当我运行页面时,它会正确显示所有游戏。它还将DropDownList正确绑定到团队。但是,当我从DropDownList更改Winning Team并单击Save时,它不会保存更改。没有错误,它只是刷新并在DropDownList中显示原始值。
代码:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="GameEdit.aspx.cs" Inherits="Pickem.Admin.GameEdit" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<rwg:BulkEditGridView ID="GameEditBulkEditGrid" DataSourceID="GameEditDataSource" AutoGenerateColumns="False"
DataKeyNames="ID,Winning Team" SaveButtonID="SaveButton" runat="server" Width="600px" EnableInsert="False" InsertRowCount="1">
<Columns>
<asp:BoundField HeaderText="ID" DataField="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" />
<asp:BoundField HeaderText="Week" DataField="Week" ReadOnly="True" SortExpression="Week" />
<asp:BoundField HeaderText="DateTime" DataField="DateTime" ReadOnly="True" SortExpression="DateTime" />
<asp:BoundField HeaderText="Home Team" DataField="Home Team" ReadOnly="True" SortExpression="HomeTeamID" />
<asp:BoundField HeaderText="Visiting Team" DataField="Visiting Team" ReadOnly="True" SortExpression="Visiting Team" />
<asp:TemplateField HeaderText="Winning Team">
<EditItemTemplate>
<asp:DropDownList ID="TeamsDropDownList" runat="server" AutoPostBack="True" DataSourceID="TeamsDataSource" DataTextField="CityShort" DataValueField="ID" SelectedValue='<%# Bind("[ID]") %>'>
</asp:DropDownList>
<asp:SqlDataSource ID="TeamsDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:PickemDb %>" SelectCommand="SELECT * FROM [Teams]"></asp:SqlDataSource>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</rwg:BulkEditGridView>
<asp:SqlDataSource ID="GameEditDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:PickemDb %>"
SelectCommand="
SELECT Games.ID, Games.Week, Games.DateTime, h.CityShort as 'Home Team', v.CityShort as 'Visiting Team', w.CityShort as 'Winning Team'
FROM [Games]
LEFT JOIN Teams h on Games.HomeTeamID = h.ID
LEFT JOIN Teams v on Games.VisitingTeamID = v.ID
LEFT JOIN Teams w on Games.WinningTeamID = w.ID
"
UpdateCommand="
UPDATE [Games]
SET [WinningTeamID] = @WinningTeamID
FROM [Games]
WHERE [ID] = @ID
">
<UpdateParameters>
<asp:Parameter Type="int32" Name="Winning Team"></asp:Parameter>
<asp:Parameter Type="int32" Name="ID"></asp:Parameter>
</UpdateParameters>
</asp:SqlDataSource>
<asp:Button ID="SaveButton" runat="server" Text="Save" />
</asp:Content>