Search code examples
c#asp.netgridviewfootertemplatefield

GridView Add TextBox TemplateField Into Footer CodeBehind


Suppose I have one template field

TemplateField FooterField = new TemplateField();

FooterField.ItemTemplate = //my code (basically setting it to display a button)

I then define what the FooterField should do during gridview editing mode like this:

FooterField.EditItemTemplate = //my code (entering editing mode when the button is clicked)

Now my question is: how can I insert this TemplateField into the gridview Footer?


Solution

  • You need to add your template field to GridView columns - each data control field essentially decides what is the contents for that column for header, footer and data rows. Grid-view being a table, you cannot have a field in footer without having column for it.

    If your requirement is to have some UI (which is not columnar in nature) in the footer then you can inherit from GridView and override CreateRow method to substitute your own UI for a footer row. However, instead of going this route, I would rather design a user control that would probably show edit UI by capturing grid-view edit event - for example, you may use Grid-View and DetailsView together.