Instead of adding total price in code behind you can give like this
CREATE TABLE ItemList
(
[ItemID] int primary key identity(1,1),
[ItemName] varchar(20),
[ItemPrice] float,
[ItemQuantity] int,
[ItemRate] AS ([ItemPrice]*[ItemQuantity])
)
here I have used calculated column([ItemRate]) for ItemList..u simply call and bind this table using grid view
<div>
<asp:gridview id="GridView1" runat="server" autogeneratecolumns="False" xmlns:asp="#unknown">
AutoGenerateEditButton="True" DataKeyNames="ItemID"
DataSourceID="ProductDataSource">
<columns>
<asp:boundfield datafield="ItemID" headertext="ItemID" insertvisible="False">
ReadOnly="True" SortExpression="ItemID" />
<asp:boundfield datafield="ItemName" headertext="ItemName">
SortExpression="ItemName" />
<asp:boundfield datafield="ItemPrice" headertext="ItemPrice">
SortExpression="ItemPrice" />
<asp:boundfield datafield="ItemQuantity" headertext="ItemQuantity">
SortExpression="ItemQuantity" />
<asp:boundfield datafield="ItemRate" headertext="ItemRate" readonly="True">
SortExpression="ItemRate" />
</asp:boundfield></asp:boundfield></asp:boundfield></asp:boundfield></asp:boundfield></columns>
</asp:gridview>
<asp:sqldatasource id="ProductDataSource" runat="server" xmlns:asp="#unknown">
ConnectionString="<%$ ConnectionStrings:PurchaseMasterConnectionString %>"
SelectCommand="SELECT * FROM [ItemList]"
UpdateCommand="Update [ItemList] set ItemQuantity=@ItemQuantity where ItemID=@ItemID "></asp:sqldatasource>
</div>
now click edit in grid change u r quantity value click update now rate will be updated automatically