0

我遇到了经典的“ 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>
4

1 回答 1

0

控件嵌套在GridViewRow实现INamingContainer接口的 a 中。如果您使用的是最新版本的 ASP.NET 并且只需要单行编辑,您应该能够通过将控件 ID 设为静态来解决此问题:

ClientIDMode="Static"
于 2013-09-27T19:01:09.600 回答