Gridview Footer Help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael

    Gridview Footer Help

    I reviewed a couple of tutorials that show how to display totals in
    the footer of a gridview. My footer shows up blank. Can someone help
    me. The code is as follows:

    <%@ Page Language="VB" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
    www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

    <script runat="server">
    Dim weighttotal As Decimal = 0
    'Dim quantityTotal As Integer = 0
    Sub detailsGridView _RowDataBound(B yVal sender As Object, _
    ByVal e As GridViewRowEven tArgs)
    If e.Row.RowType = DataControlRowT ype.DataRow Then
    ' add the UnitPrice and QuantityTotal to the running total
    variables
    weighttotal +=
    Convert.ToDecim al(DataBinder.E val(e.Row.DataI tem, _
    "scale1"))
    ElseIf e.Row.RowType = DataControlRowT ype.Footer Then
    e.Row.Cells(1). Text = "Totals:"
    e.Row.Cells(2). Text = weighttotal.ToS tring()

    e.Row.Cells(1). HorizontalAlign = HorizontalAlign .Right
    e.Row.Cells(2). HorizontalAlign = HorizontalAlign .Right
    e.Row.Font.Bold = True
    End If
    End Sub


    </script>

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Untitl ed Page</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:GridView ID="GridView1" runat="server"
    AutoGenerateCol umns="False" DataKeyNames="I D"
    showfooter=true
    DataSourceID="A ccessDataSource 1" Style="z-index: 100;
    left: 88px; position: absolute;
    top: 115px">
    <Columns>
    <asp:BoundFie ld DataField="ID" HeaderText="ID"
    InsertVisible=" False" ReadOnly="True"
    SortExpression= "ID" />
    <asp:BoundFie ld DataField="Scal e1" HeaderText="Sca le1"
    SortExpression= "Scale1" />
    <asp:BoundFie ld DataField="Scal e2" HeaderText="Sca le2"
    SortExpression= "Scale2" />
    <asp:BoundFie ld DataField="Empl oyee"
    HeaderText="Emp loyee" SortExpression= "Employee" />
    </Columns>
    </asp:GridView>
    <asp:AccessData Source ID="AccessDataS ource1" runat="server"
    DataFile="~/App_Data/Spare_Parts_II_ BCPC.mdb"
    SelectCommand=" SELECT * FROM [Scrap]"></
    asp:AccessDataS ource>

    </div>
    </form>
    </body>
    </html>
  • ThatsIT.net.au

    #2
    Re: Gridview Footer Help

    I think your problem is trying to access cells in the foota when there isn't
    any.
    Put a table in the foota and use find control to access it
    here is a example using a repeater

    If e.Item.ItemType = ListItemType.Fo oter Then
    Dim footaTab As Table = e.Item.FindCont rol("Table1")
    Dim tc As TableCell = New TableCell
    tc.Text = "5555"
    footaTab.Rows(0 ).Cells.Add(tc)
    End If







    "Michael" <bgreer5050@gma il.comwrote in message
    news:893cbd08-ec19-4408-ac44-4b8676598532@59 g2000hsb.google groups.com...
    >I reviewed a couple of tutorials that show how to display totals in
    the footer of a gridview. My footer shows up blank. Can someone help
    me. The code is as follows:
    >
    <%@ Page Language="VB" %>
    >
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
    www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
    >
    <script runat="server">
    Dim weighttotal As Decimal = 0
    'Dim quantityTotal As Integer = 0
    Sub detailsGridView _RowDataBound(B yVal sender As Object, _
    ByVal e As GridViewRowEven tArgs)
    If e.Row.RowType = DataControlRowT ype.DataRow Then
    ' add the UnitPrice and QuantityTotal to the running total
    variables
    weighttotal +=
    Convert.ToDecim al(DataBinder.E val(e.Row.DataI tem, _
    "scale1"))
    ElseIf e.Row.RowType = DataControlRowT ype.Footer Then
    e.Row.Cells(1). Text = "Totals:"
    e.Row.Cells(2). Text = weighttotal.ToS tring()
    >
    e.Row.Cells(1). HorizontalAlign = HorizontalAlign .Right
    e.Row.Cells(2). HorizontalAlign = HorizontalAlign .Right
    e.Row.Font.Bold = True
    End If
    End Sub
    >
    >
    </script>
    >
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Untitl ed Page</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:GridView ID="GridView1" runat="server"
    AutoGenerateCol umns="False" DataKeyNames="I D"
    showfooter=true
    DataSourceID="A ccessDataSource 1" Style="z-index: 100;
    left: 88px; position: absolute;
    top: 115px">
    <Columns>
    <asp:BoundFie ld DataField="ID" HeaderText="ID"
    InsertVisible=" False" ReadOnly="True"
    SortExpression= "ID" />
    <asp:BoundFie ld DataField="Scal e1" HeaderText="Sca le1"
    SortExpression= "Scale1" />
    <asp:BoundFie ld DataField="Scal e2" HeaderText="Sca le2"
    SortExpression= "Scale2" />
    <asp:BoundFie ld DataField="Empl oyee"
    HeaderText="Emp loyee" SortExpression= "Employee" />
    </Columns>
    </asp:GridView>
    <asp:AccessData Source ID="AccessDataS ource1" runat="server"
    DataFile="~/App_Data/Spare_Parts_II_ BCPC.mdb"
    SelectCommand=" SELECT * FROM [Scrap]"></
    asp:AccessDataS ource>
    >
    </div>
    </form>
    </body>
    </html>

    Comment

    Working...