2
Answers

How to add Column and Row for total in datagrid

Mithila Das

Mithila Das

1d
55
1

 

I have populated my data in datagrid1. Here is my code.

SqlCommand cmd = new SqlCommand("SELECT ID, Item, ItemPrice, Quantity, FROM tblItem", conn.con);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataTable table = new DataTable();
adapter.Fill(table);
datagrid1.DataSource = table;

My output is:

ID Item ItemPrice Quantity
1 Mango $10 10
2 Coconut $30 15
3 Apple $15 20

I want to add Extra Column and a row in footer for calculation like below:

ID Item ItemPrice Quantity Total
1 Mango $10 10 $100
2 Coconut $30 15 $450
3 Apple $15 20 $300
      Total: $850

How can i populate and calculate my data in datagrid like this?

Answers (2)