Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
Hi,

I am trying to add a total to the bottom of a DataBound GridView. I recently asked how to acheive this on here and I got the help I needed.

After following one of the tutorials that were given in the answer. I now have an error, everytime the page try's to load.

The error I am receiving is... "Compiler Error Message: BC30456: 'grvAgentStats_RowDataBound' is not a member of 'ASP.stats_aspx'."

I'm not too sure why I am receiving this and I have posted the code for both the ASP.net page and the VB.Net Code-behind.

ASP.Net "Stats.aspx"
XML
<asp:Button ID="btnView" runat="server" Text="View" cssClass="btnASView" /><br /><br />
    <asp:GridView ID="grvAgentStats" runat="server" AutoGenerateColumns="False" CellPadding="4"
        ForeColor="#333333" GridLines="None" Style="font-size: 12px" Width="500px" ShowFooter="True"
        OnRowDataBound="grvAgentStats_RowDataBound">
        <AlternatingRowStyle BackColor="White" />
        <Columns>
            <asp:BoundField DataField="Result" HeaderText="Result" ItemStyle-Wrap="false" ItemStyle-HorizontalAlign="Left" />
            <asp:TemplateField HeaderText="Amount">
                <ItemTemplate>
                    <asp:Label ID="lblAmount" runat="server" Text='<%# Eval("Amount") %>' />
                </ItemTemplate>
                <FooterTemplate>
                    <asp:Label ID="lblTotalAmount" runat="server" />
                </FooterTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="At" HeaderText="@" ItemStyle-Wrap="false" ItemStyle-HorizontalAlign="Left" />
            <asp:BoundField DataField="Fee" HeaderText="Fee" ItemStyle-Wrap="false" ItemStyle-HorizontalAlign="Left" />
            <asp:BoundField DataField="Equals" HeaderText="=" ItemStyle-Wrap="false" ItemStyle-HorizontalAlign="Left" />
            <asp:TemplateField HeaderText="Total">
                <ItemTemplate>
                    <asp:Label ID="lblTotal" runat="server" Text='<%# Eval("Total") %>' />
                </ItemTemplate>
                <FooterTemplate>
                    <asp:Label ID="lblTotalFee" runat="server" />
                </FooterTemplate>
            </asp:TemplateField>
        </Columns>
        <EditRowStyle BackColor="#2461BF" />
        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" HorizontalAlign="Center" />
        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#EFF3FB" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
        <SortedAscendingCellStyle BackColor="#F5F7FB" />
        <SortedAscendingHeaderStyle BackColor="#6D95E1" />
        <SortedDescendingCellStyle BackColor="#E9EBEF" />
        <SortedDescendingHeaderStyle BackColor="#4870BE" />
    </asp:GridView>


"Stats.aspx" Code-Behind
VB
Private Sub DatabindResults()
        Dim SQLconn As SqlConnection
        Dim SQLComm As SqlCommand
        Dim SQLDa As SqlDataAdapter
        Dim SQLDt As DataTable
        Dim ADUsername As String = Session.Item("txtUsername")

        Dim Date1 As String = ddlDates.SelectedValue
        Dim ClientName As String = ddlClient.SelectedValue

        SQLconn = New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)

        SQLComm = New SqlCommand("prcHHGenAgentStats_New", SQLconn)
        SQLComm.CommandType = CommandType.StoredProcedure
        SQLComm.Parameters.AddWithValue("@Month", 8)
        SQLComm.Parameters.AddWithValue("@ADUserName", ADUsername)
        SQLComm.Parameters.AddWithValue("@ClientName", "Client")

        SQLDa = New SqlDataAdapter(SQLComm)
        SQLDt = New DataTable()

        SQLDa.Fill(SQLDt)
        grvAgentStats.DataSource = SQLDt
        grvAgentStats.DataBind()
    End Sub

    Private Sub btnView_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnView.Click
        DatabindResults()
    End Sub

    Private Sub grvAgentStats_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grvAgentStats.RowDataBound
        Dim TotalAmount As Decimal
        Dim TotalFee As Decimal
        If e.Row.RowType = DataControlRowType.DataRow Then

            Dim lblAmount As Label = e.Row.FindControl("lblAmount")
            Dim lblTotal As Label = e.Row.FindControl("lblTotal")

            Dim Amount As Decimal = Decimal.Parse(lblAmount.Text)
            Dim Total As Decimal = Decimal.Parse(lblTotal.Text)

            TotalAmount += Amount
            TotalFee += Total

            If e.Row.RowType = DataControlRowType.Footer Then
                Dim lblTotalPrice As Label = DirectCast(e.Row.FindControl("lblAmount"), Label)
                Dim lblTotalUnitsInStock As Label = DirectCast(e.Row.FindControl("lblTotal"), Label)

                lblTotalPrice.Text = TotalAmount.ToString()
                lblTotalUnitsInStock.Text = TotalFee.ToString()

            End If

        End If
    End Sub


Any help on this one will be greatly appreciated as it's really starting to bug me now loll.

P.S - I've searched for about an hour on both here and google, and I bet someone find something that will help me lol!!

Thanks,
JammoD
Posted

It looks as if Visual Studio is confused. The event you mentioned, does exist in the code. What you can do is try restarting Visual Studio and running. If that does not help, try cleaning out the temporary asp.net websites folder located at
Quote:
C:\Windows\Microsoft.NET\Framework\{version}\Temporary ASP.NET Files

I know it sounds stupid but sometimes it does work perfectly. If you have windows installed in different directory, then make sure that you replace the drive letter. And also replace the {version} placeholder with the framework version you are developing. You can just browse to that directory and do it :)

Do let me know if this helps. If not, I will modify the answer accordingly.
 
Share this answer
 
Comments
JammoD87 6-Aug-12 10:32am    
Hi,

Thanks for the fast response!

I've just tried the solution you posted and neither of them seemed to work in this case :(

Thanks :)
Pankaj Nikam 6-Aug-12 10:50am    
Try commenting the handler in the code in codebehind and then in the code view (aspx), remove the attribute OnRowDataBound="grvAgentStats_RowDataBound" and go to the design view, select the GridView and go to its properties, then events, and on the RowDataBound, double click in the empty area to create a skeleton of the handler in the code behind. Paste the commented code and uncomment it.

Try this and let me know
JammoD87 6-Aug-12 11:19am    
Hi,

That work, bit of a strange one, have to remeber that for the future!

On to the next problem now lol.

Thanks for your help.
Pankaj Nikam 6-Aug-12 12:20pm    
Yup I know its strange... Sometimes Visual Studio tricks us ;)
Anyway happy to help you :)
Hi Friends,

I am also acing same pronlem
after changes the error occured like this

Method 'Protected Sub GridmailDetails_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewCommandEventArgs)' cannot handle event 'Public Event RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs)' because they do not have a compatible signature

Share me our knowledge

Regards,
Velsamy A
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900