我遇到了经典的“ EditItemTemplate ”/“ Cannot find Control ”错误,因为我的搜索参数引用了GridView内的EditItemTemplate内的ControlID。我尝试在我的 ControlID 前面加上 GridView 的 ID(gridview$controlID),但它不起作用。如果必须,我很乐意使用“代码隐藏”方法,但我更愿意理解为什么前置方法不起作用。基于以下代码的任何提示?
谢谢!
<asp:UpdatePanel ID="upMatchEntry" ChildrenAsTriggers="false" EnableViewState="false" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlGameWeek" EventName="SelectedIndexChanged" />
</Triggers>
<ContentTemplate>
<asp:GridView ID="gvMatchSelect" DataKeyNames="MatchID,HomeTeamID,AwayTeamID"
DataSourceID="sdsMatches" runat="server" AutoGenerateEditButton="True"
AutoGenerateColumns="False" EmptyDataText="No Matches Found" ContentPlaceHolderID="cpMatchSelect">
<Columns>
<asp:TemplateField HeaderText="Home Team" SortExpression="HomeTeamName" ItemStyle-HorizontalAlign="left">
<ItemTemplate><%# Eval("HomeTeamName") %></ItemTemplate>
<EditItemTemplate>
<asp:DropDownList runat="server" ID="ddlHomeTeam" DataSourceID="sdsHomeTeams"
DataTextField="HomeTeamName" DataValueField="HomeTeamID"
SelectedValue='<%# Bind("HomeTeamID") %>' AutoPostBack="True" />
</EditItemTemplate>
<ItemStyle HorizontalAlign="Left" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Away Team" SortExpression="AwayTeamName" ItemStyle-HorizontalAlign="left">
<ItemTemplate><%# Eval("AwayTeamName") %></ItemTemplate>
<EditItemTemplate>
<asp:DropDownList runat="server" ID="ddlAwayTeam" DataSourceID="sdsAwayTeams"
DataTextField="AwayTeamName" DataValueField="AwayTeamID"
SelectedValue='<%# Bind("AwayTeamID") %>' AutoPostBack="True"/>
</EditItemTemplate>
<ItemStyle HorizontalAlign="Left" />
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="sdsMatches" ConnectionString='<%$ ConnectionStrings:ApplicationServices %>' runat="server"
SelectCommand="pGameWeekMatchAdminDisplay" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter Name="GameWeekID" ControlID="ddlGameWeek" PropertyName="SelectedValue" Type="Int32" DefaultValue="-1" />
<asp:ControlParameter Name="DivisionID" ControlID="ddlDivision" PropertyName="SelectedValue" Type="Int32" DefaultValue="-1" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="sdsHomeTeams" ConnectionString='<%$ ConnectionStrings:ApplicationServices %>' runat="server"
SelectCommand="SELECT 'Select Home Team' AS HomeTeamName, -1 AS HomeTeamID UNION SELECT Name AS HomeTeamName, TeamID AS HomeTeamID FROM Team WHERE DivisionID = @DivisionID AND TeamID <> @AwayTeamID" >
<SelectParameters>
<asp:ControlParameter Name="DivisionID" ControlID="ddlDivision" PropertyName="SelectedValue" Type="Int32" />
<asp:ControlParameter Name="AwayTeamID" ControlID="gvMatchSelect$ddlAwayTeam" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="sdsAwayTeams" ConnectionString='<%$ ConnectionStrings:ApplicationServices %>' runat="server"
SelectCommand="SELECT 'Select Away Team' AS AwayTeamName, -1 AS AwayTeamID UNION SELECT Name AS AwayTeamName, TeamID AS AwayTeamID FROM Team WHERE DivisionID = @DivisionID AND TeamID <> @HomeTeamID" >
<SelectParameters>
<asp:ControlParameter Name="DivisionID" ControlID="ddlDivision" PropertyName="SelectedValue" Type="Int32" />
<asp:ControlParameter Name="HomeTeamID" ControlID="gvMatchSelect$ddlHomeTeam" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</ContentTemplate>
</asp:UpdatePanel>