1
votes

I have a gridView that I wish to add a textbox to. I want the textbox to be located in the footer, but I have no idea how to do that.

This is my gridview:

<asp:GridView ID="gvTest" runat="server" AutoGenerateColumns="false"
                 AllowSorting="True"
                 ShowFooter="True"
                 ShowHeaderWhenEmpty="true"
                 OnRowDataBound="gvTest_RowDataBound"
                 Width="550px">                                         
    <EmptyDataTemplate>
        No data.
    </EmptyDataTemplate>
    <Columns>
        <asp:BoundField DataField="Name" headerText="Name"/>
        <asp:TemplateField>
            <HeaderTemplate>
                Actions
            </HeaderTemplate>
            <ItemTemplate>
                 <asp:ImageButton ID="imbView" runat="server" ToolTip="View details" ImageUrl="~/css/images/Search.png" Width="16" />
            </ItemTemplate>
        </asp:TemplateField>                     
    </Columns>
</asp:GridView>

I've seen people talking about adding something like this:

<FooterTemplate>
    <asp:TextBox ID="tbName" runat="server"/>
</FooterTemplate>

But I dont know where or how to add it. If I just put it in between the <asp:TemplateField>tags it messes up (probably because my boundfields).

Additional information:

I bind the gridview using DataTable. The real table has more columns, but this will suffice for an example.

2

2 Answers

4
votes

Switch from:

<asp:TemplateField>
        <HeaderTemplate>
            Actions
        </HeaderTemplate>
        <ItemTemplate>
             <asp:ImageButton ID="imbView" runat="server" ToolTip="View details" ImageUrl="~/css/images/Search.png" Width="16" />
        </ItemTemplate>
    </asp:TemplateField>               

to:

<asp:TemplateField>
        <HeaderTemplate>
            Actions
        </HeaderTemplate>
        <ItemTemplate>
             <asp:ImageButton ID="imbView" runat="server" ToolTip="View details" ImageUrl="~/css/images/Search.png" Width="16" />
        </ItemTemplate>
        <FooterTemplate>
            <asp:TextBox ID="tbName" runat="server"/>
        </FooterTemplate>
    </asp:TemplateField>               

It's easy if you understand, that you can devide your TemplateField into three sections:

  1. Header
  2. Item(or main content)
  3. Footer

Greetz

0
votes

You will need to put it in the template field.. like this..

<asp:TemplateField HeaderText="BankName" SortExpression="BankName">
        <EditItemTemplate>
             <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("BankName") %>'></asp:TextBox>
         </EditItemTemplate>
         <ItemTemplate>
             <asp:Label ID="Label2" runat="server" Text='<%# Bind("BankName") %>'></asp:Label>
         </ItemTemplate>
         <FooterTemplate>
               <asp:TextBox ID="tbAddBankName" runat="server"></asp:TextBox>
         </FooterTemplate>
         <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:TemplateField>

this is an example from my working code.