【问题标题】:dropdownlist in a footer of gridviewgridview 页脚中的下拉列表
【发布时间】:2013-01-07 05:27:03
【问题描述】:

我有 asp 网格视图,我创建了 4 列(ID、名称、数量、价格)和一个页脚。我已经限制了数据库中的所有 4 列。在页脚模板中,我添加了一个下拉列表项。 一切正常,但问题是在所有 4 列之后添加了页脚模板下拉列表,但我想将下拉页脚添加到第二列(名称)。

请为我的英语道歉 n 帮助我

我使用了以下代码:

<asp:GridView ID="gv_page2" runat="server" AutoGenerateColumns="False" 
            BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" 
            CellPadding="3" ForeColor="Black" GridLines="Vertical" ShowFooter="True"> 
          <AlternatingRowStyle BackColor="#CCCCCC" />
          <FooterStyle BackColor="Black" />
          <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
          <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
          <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
          <SortedAscendingCellStyle BackColor="#F1F1F1" />
          <SortedAscendingHeaderStyle BackColor="#808080" />
          <SortedDescendingCellStyle BackColor="#CAC9C9" />
          <SortedDescendingHeaderStyle BackColor="#383838" />
          <Columns>
          <asp:BoundField  DataField="PRO_ID" HeaderText="PRO_ID" />
          <asp:BoundField DataField="NAME" HeaderText="NAME" ItemStyle-Width="100px"/>
          <asp:TemplateField HeaderText="Quantity">
          <ItemTemplate> <asp:TextBox runat="server" Width="100px"></asp:TextBox></ItemTemplate>
          </asp:TemplateField>
          <asp:BoundField HeaderText="PRICE" ItemStyle-Width="80px"/>
          <asp:BoundField  HeaderText="TOTAL_PRICE"/>
          <asp:TemplateField>
          <FooterTempenter code herelate >
          <asp:DropDownList  ID="ftrDDL" runat="server" DataTextField="PRO_ID" AppendDataBoundItems="true" DataSourceID="" Width="130px" EnableViewState="true" >
          <asp:ListItem Text="SELECT ONE" Value=""></asp:ListItem>
          </asp:DropDownList>
          </FooterTemplate>
          </asp:TemplateField>
          </Columns>

    </asp:GridView>

【问题讨论】:

    标签: asp.net gridview


    【解决方案1】:

    需要修改第二列的模板

     <asp:TemplateField HeaderText="Name">
                <ItemTemplate>
                    <asp:Label ID="lblName" Text='<%#     Databinder.Eval(Container.DataItem,"Name") %>'
                        runat="server" Width="100px"></asp:Label></ItemTemplate>
                    <FooterTemplate>
                    <asp:DropDownList ID="ftrDDL" runat="server" DataTextField="PRO_ID" AppendDataBoundItems="true"
                        DataSourceID="" Width="130px" EnableViewState="true">
                        <asp:ListItem Text="SELECT ONE" Value=""></asp:ListItem>
                </FooterTemplate>
            </asp:TemplateField>
    

    我还没有测试过代码,但这应该可以工作。如果它不起作用,请告诉我

    【讨论】:

      【解决方案2】:

      是否需要在页脚中添加下拉列表?

      我建议将下拉列表添加到名称列。页脚将始终最后加载。

      【讨论】:

        【解决方案3】:

        为名称使用模板文件

        <asp:GridView ID="gv_page2" runat="server" AutoGenerateColumns="False" BackColor="White"
                    BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" ForeColor="Black"
                    GridLines="Vertical" ShowFooter="True">
                    <AlternatingRowStyle BackColor="#CCCCCC" />
                    <FooterStyle BackColor="Black" />
                    <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
                    <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
                    <SortedAscendingCellStyle BackColor="#F1F1F1" />
                    <SortedAscendingHeaderStyle BackColor="#808080" />
                    <SortedDescendingCellStyle BackColor="#CAC9C9" />
                    <SortedDescendingHeaderStyle BackColor="#383838" />
                    <Columns>
                        <asp:BoundField DataField="PRO_ID" HeaderText="PRO_ID" />
                        <asp:TemplateField HeaderText="Name">
                            <ItemTemplate>
        
                            </ItemTemplate>
                            <FooterTemplate>
                                <asp:DropDownList ID="ftrDDL" runat="server" DataTextField="PRO_ID" AppendDataBoundItems="true"
                                    DataSourceID="" Width="130px" EnableViewState="true">
                                </asp:DropDownList>
                            </FooterTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Quantity">
                            <ItemTemplate>
                                <asp:TextBox ID="TextBox1" runat="server" Width="100px"></asp:TextBox></ItemTemplate>
                        </asp:TemplateField>
                        <asp:BoundField HeaderText="PRICE" ItemStyle-Width="80px">
                            <ItemStyle Width="80px"></ItemStyle>
                        </asp:BoundField>
                        <asp:BoundField HeaderText="TOTAL_PRICE" />
                    </Columns>
                </asp:GridView>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多