1

this the datagrid i got

+==========+==========+==========+==========+
| Product  |  Price   | quantity |   Total  |
+==========+==========+==========+==========+

so i got Product and Price from MySQL database (Table1). and user enter number in the quantity cell and the program calculat the Total (Total=Price*quantity) the save it in Table2 (in MySQL).

this is an example

+==========+==========+==========+==========+
| Product  |  Price   | quantity |   Total  |
+==========+==========+==========+==========+
|  AAAAA   |    30    |    2     |    60    |
+==========+==========+==========+==========+

UPDATE

I add CellEditEndding handler like this

private void Produit_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
    {
        DataTable dt = new DataTable();
        dt = ((DataView)Produit.ItemsSource).ToTable();
        foreach (DataRow row in dt.Rows)
        {
            row["total"] = (Convert.ToDouble(row["price"]) * Convert.ToDouble(row["quantity"]));
        }
        Produit.ItemsSource = dt.DefaultView;
    }

when i edit a quantity cell every thing is return to 0.

NOTE: when I'm filling the DataGrid i Fill quantity an total with zoros

Ilyas Ghomrani
  • 408
  • 6
  • 26

1 Answers1

0

As i understand your question, you want to ask that the user just enter the product code and quantity then the price and total-price automatically add to the data grid view. For that purpose you need to add Label field with the help of TemplateField in your data grid column Like this

      <Columns>
                    <asp:TemplateField>
                        <ItemTemplate>
                            <asp:Label ID="lblprice" runat="server"></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
 <asp:TemplateField>
                        <ItemTemplate>
                            <asp:Label ID="lblTotalPrice" runat="server"></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
    </Columns>

Then access the label to server side

Label lblprice= (Label)row.FindControl("lblprice");
Label lblTotalPrice= (Label)row.FindControl("lblTotalPrice");

Now just assign the values to these labels.

Waleed Manzoor
  • 95
  • 1
  • 11