Click here to Skip to main content
14,738,280 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In the winform app i have datagridview which has GoodsName column and Price column. I want to know how can i make a new row so that i can see the sum of price in it.
Any help will be appreciated

Hi ,
Check this
protected void Page_Load(object sender, EventArgs e)
    if (!IsPostBack)
        var result = from x in db.tests
                     select x;

        GridView1.DataSource = result;

} int sum = 0;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

    if (e.Row.RowType == DataControlRowType.DataRow)
         sum += Convert.ToInt32(((Label)e.Row.FindControl("lbl2")).Text);
    if (e.Row.RowType == DataControlRowType.Footer)
        ((Label)e.Row.FindControl("lblCalc")).Text = sum.ToString();

       <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"

           onrowdatabound="GridView1_RowDataBound" ShowFooter="True">
               <asp:TemplateField HeaderText="ID">
                       <asp:Label ID="Label1" runat="server" Text="<%# Bind('id') %>"></asp:Label>
               <asp:TemplateField HeaderText="calc">
                       <asp:Label ID="lblCalc" runat="server" Text="Label"></asp:Label>
                       <asp:Label ID="lbl2" runat="server" Text="<%# Bind('company') %>"></asp:Label>

Best Regards
I hope This will help u:

Summary DataGridView[^]
The following code sample shows how to display text in GridView Footer.


1) Set GridView ShowFooter property to true

2) Write the below code in GridView_RowdataBound Event

if ( e.Row.RowType == DataControlRowType.DataRow )
            sum = sum + Convert.ToInt32 ( e.Row.Cells [ 0 ].Text );

        else if ( e.Row.RowType == DataControlRowType.Footer )
            e.Row.Cells [ 0 ].Text = sum.ToString ( "c" );
aliprogrammer 6-May-12 16:31pm
how to show the result in a new row under the intention column?
Member 10659195 17-Apr-14 15:20pm
i have a gridview bound to database and it has column named product_name,price/unit now i have to provide multiple quantity of such products and multiple products are to be selected by the customer and also show the entire shopping data at a single field with the total amount and amount of each entity
pl. help me out brother

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