页脚中的DropDownList未填充/绑定

时间:2017-02-22 12:52:24

标签: c# html asp.net gridview drop-down-menu

我有一个包含两个DropDownLists的GridView。对于DataRecord,DropDownLists完全填充/绑定,但对于页脚,它们保持空/未绑定。在DataRecord和Footer中,DropDownLists分别具有相同的SqlDataSource。什么原因可能是页脚中的DropDownLists没有被填充/绑定?

               <asp:GridView
                    ID="ExecutionGridView"
                    runat="server"
                    AutoGenerateColumns="False"
                    DataKeyNames="ID"
                    Font-Names="Calibri"
                    Font-Size="Small"
                    OnRowCommand="ExecutionGridView_RowCommand"
                    OnRowDataBound="ExecutionGridView_RowDataBound"
                    OnRowDeleting="ExecutionGridView_RowDeleting"
                    OnRowUpdating="ExecutionGridView_RowUpdating" 
                    HorizontalAlign="Left"         
                    ShowFooter="true"               
                    Visible="False">
                    <FooterStyle Font-Names="Calibri" Font-Size="Small" />
                    <HeaderStyle Font-Names="Calibri" Font-Size="Small" HorizontalAlign="Left" CssClass="headerClass" ForeColor="#408080" BackColor="White" BorderColor="#408080" />
                    <Columns>                            
                        <asp:TemplateField HeaderText="ID" ItemStyle-Width="30">
                            <ItemTemplate>
                                <%# Eval("ID") %>
                                <input type="hidden" name="ExecutionId" value='<%# Eval("ID") %>' />
                            </ItemTemplate>
                            <ItemStyle Width="30px" />
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Theme" SortExpression="ThemeID">
                            <ItemTemplate>
                                <asp:DropDownList ID="ThemesIDDropDownList" runat="server" DataSourceID="ThemesSqlDataSource" DataTextField="Theme" DataValueField="ID" CssClass="ddl" SelectedValue='<%# Bind("ThemeID", "{0:D}") %>' AutoPostBack="True"></asp:DropDownList>
                            </ItemTemplate>
                            <FooterTemplate>
                                <asp:DropDownList ID="ThemesIDDropDownList1" runat="server" DataSourceID="ThemesSqlDataSource" DataTextField="Theme" DataValueField="ID" CssClass="ddl" ></asp:DropDownList>
                            </FooterTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Env" SortExpression="EnvironmentID">
                            <ItemTemplate>
                                <asp:DropDownList ID="EnvironmentsIDDropDownList" runat="server" DataSourceID="EnvironmentsSqlDataSource" DataTextField="Environment" DataValueField="ID" CssClass="ddl" SelectedValue='<%# Bind("EnvironmentID", "{0:D}") %>' AutoPostBack="True"></asp:DropDownList>
                            </ItemTemplate>
                            <FooterTemplate>
                                <asp:DropDownList ID="EnvironmentsIDDropDownList1" runat="server" DataSourceID="EnvironmentsSqlDataSource" DataTextField="Environment" DataValueField="ID" CssClass="ddl"></asp:DropDownList>
                            </FooterTemplate>
                    </asp:TemplateField>
                    </Columns>
                </asp:GridView>

1 个答案:

答案 0 :(得分:0)

FooterTemplate不会与gridview数据源的每一行一起呈现,因此无法使用模板进行绑定。我认为你应该通过代码手动完成。您可以查看此链接DropDownList control inside the GridView FooterTemplate