Hi, I was asked this in an Interview I want to add buttons,images,etc to the footer of a datagrid at runtime. how would i achieve this?

Showing Answers 1 - 13 of 13 Answers

M.Nagababu

  • Oct 18th, 2006
 

Hi,Yatin

       to added controls to the footer of the datagrid we use <footer Template> </footer template> command in <template columns> </template colums>. For example we a button control in a footer of datagrid like this:

<datagrid><columns><template columns><footer template><asp:button id= btn1 label = button runat = server></asp:button></footer template></template columns></columns></datagrid>

in the same way we add controls to header also. by using <header template></header template>

  Was this answer useful?  Yes

anjani

  • Jul 15th, 2008
 

hi

Add buttons,images,etc to the footer in the data grid u use the template field conept in the html file

<Columns>

    <asp:TemplateField>
     
    <HeaderTemplate>
        HTML,TEXT,SERVER
      </HeaderTemplate>

     <ItemTemplate>
       HTML,TEXT,SERVER
      </ItemTemplate>


      <FooterTemplate>
      <asp:Button ID="Btn_Add" runat="server" CommandName="AddUser" Text="Add"/>
      </FooterTemplate>
        
    </asp:TemplateField>
   
     </Columns>

from that coding a button will be add in the footer of the gridview in the similar way we can add other controls also.

  Was this answer useful?  Yes

nt57323

  • Mar 25th, 2009
 

You can add the controls in the footer similar to the way how you add a control for a column.
If you want to add the control in the footer, you should take template field. In the template field you will be having footer template. Just drag and drop the control which ever you like.

  Was this answer useful?  Yes

albu77

  • Jun 1st, 2009
 

As they ask you to do it at run time, you need to add the controls to the control collection of the cell of the footer row of the gridView.
Button myBtn = new Button();

gvTest.FooterRow.Cells[1].Controls.Add(myBtn);

Play caution where the dynamic addition is done if you want it to persist.

  Was this answer useful?  Yes

At design time, we can add button in footer template of the grid.

<asp:TemplateField>
....
<FooterTemplate>
<asp:Label ID="lblTotalInvoiceAmount" runat="server" Text=''></asp:Label>
</FooterTemplate>
</asp:TemplateField>

At runtime,

Private Sub DataGrid1_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemCreated
If (e.Item.ItemType = ListItemType.Footer) Then
e.Item.Cells(2).Text = "Total&nbsp;"
e.Item.Cells(2).HorizontalAlign = HorizontalAlign.Right
Dim oTextbox As New TextBox
oTextbox.Width = New Unit(100, UnitType.Pixel)
oTextbox.Text = "90.3500" 'This can be changed to populate from some datasource.
e.Item.Cells(3).Controls.Add(oTextbox)
End If
End Sub

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions