How do I add FooterTemplate to GridView with BoundFields
You can try with
<columns>
<asp:templatefield headertext="Test" >
<itemtemplate>
....
</itemtemplate>
<footertemplate>
<asp:TextBox id="TestTbx" runat="server"/>
</footertemplate>
</asp:templatefield>
</columns>
Link : http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.templatefield.footertemplate.aspx
Thomas BP
I'm a sparetime TYPO3 user, have some experience with ASP.NET and PHP but is not a pro. I'm using this helpfull place/site to get some more experience, with this wonderfull coding world.
Updated on July 18, 2020Comments
-
Thomas BP almost 4 years
Hope you have a good weekend. At long last I have got some editing/delete eventer to work with LINQ support. I have an Add record event which I know is working, but after trying a part, I do not know how I am adding some textbox's in my footer.
So it is a row from header and down to footer, without the move to the right or the left. Can some help me !?
My code is
<asp:GridView ID="gdview" runat="server" AutoGenerateColumns="False" DataKeyNames="test_id" OnRowCancelingEdit="gdview_RowCancelingEdit" OnRowDeleting="gdview_RowDeleting" OnRowEditing="gdview_RowEditing" OnRowUpdating="gdview_RowUpdating" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal" ShowFooter="true"> <Columns> <asp:BoundField HeaderText="Test CAT" DataField="test_cat"> <ItemStyle Height="20px" Width="150px" /> </asp:BoundField> <asp:BoundField HeaderText="Test INFO" DataField="test_info"> <ItemStyle Height="20px" Width="150px" /> </asp:BoundField> <asp:BoundField HeaderText="Test NUMBER" DataField="test_number"> <ItemStyle Height="20px" Width="150px" /> </asp:BoundField> <asp:BoundField HeaderText="Test DATE" DataField="test_datetime"> <ItemStyle Height="20px" Width="150px" /> </asp:BoundField> <asp:CommandField ShowEditButton="True"> <ItemStyle Width="100px" /> </asp:CommandField> <asp:TemplateField> <ItemTemplate> <asp:LinkButton ID="lnkdel" runat="server" Text="Delete" CommandName="Delete" OnClientClick="return confirm('Do you want to delete?')"></asp:LinkButton> </ItemTemplate> <ItemStyle Width="100px" /> </asp:TemplateField> </Columns> <FooterStyle BackColor="#CCCC99" ForeColor="Black" /> <HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" /> <SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" /> <SortedAscendingCellStyle BackColor="#F7F7F7" /> <SortedAscendingHeaderStyle BackColor="#4B4B4B" /> <SortedDescendingCellStyle BackColor="#E5E5E5" /> <SortedDescendingHeaderStyle BackColor="#242121" /> </asp:GridView>
Ok but how with this then work, if i use templates, how do it know what cell to get values from !??
Protected Sub gdview_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs) Using db As New ThedatabaseconnectionDataContext() Try 'getting table Dim tbltest As Table(Of testtable) = db.GetTable(Of testtable)() 'getting an exiting row Dim objtest As testtable = tbltest.SingleOrDefault(Function(p) p.test_id = Integer.Parse(gdview.DataKeys(e.RowIndex).Value.ToString())) If objtest IsNot Nothing Then 'modifying the row objtest.test_cat = DirectCast(gdview.Rows(e.RowIndex).Cells(0).Controls(0), TextBox).Text objtest.test_info = DirectCast(gdview.Rows(e.RowIndex).Cells(1).Controls(0), TextBox).Text objtest.test_number = DirectCast(gdview.Rows(e.RowIndex).Cells(2).Controls(0), TextBox).Text objtest.test_datetime = DirectCast(gdview.Rows(e.RowIndex).Cells(3).Controls(0), TextBox).Text 'saving rows added db.SubmitChanges() gdview.EditIndex = -1 bindgrid() ' Me.lblMsg.Text = "Updated Successfully" Else 'Me.lblMsg.Text = "Employee not found" End If Catch ex As Exception 'Me.lblMsg.Text = ex.Message End Try End Using
-
Aghilas Yakoub over 11 years@Thomas Replace your boundfield with templatefield and add footer, boundfield is basic field , you cannot customize, i you wish customize you must develop another boundfield and override basic behavior
-
Thomas BP over 11 yearsHi Aghilas, plz see my add..Code Behind.
-
Aghilas Yakoub over 11 yearsYou modify your code with e.Item.FindControl("IdOfControlInRow")
-
Thomas BP over 11 yearsOk so i dont need to add edittemplates to get the edit working then !?
-
bonCodigo almost 10 yearsYou need
EditTemplate
if you are planning to edit this field (which now is aBoundField
). Usually columns which were defined asBoundField
don't seem to be editted on run time. I assume the same case for you. You just want to insert but no edit. So as @AghilasYakoub demonstrated, it's just atemplatefield
to support the functionalists ofinsert
usingFooterTemplate