Click here to Skip to main content
15,909,822 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can Anyone know this please help me.....


i Have to calculate total price of items present in gridview rows and quantity of item is editable..if i change quantity 1 to means it calculate dynamically also...total price placed outside the gridview...ple anyone give C# coding for this..
Posted
Comments
Balakrishnan Dhinakaran 5-Dec-11 23:56pm    
your question is not so clear...Do you want to calculate the value out the Grid view if the Quantity changes dynamically?
M.Narmatha 5-Dec-11 23:57pm    
yes....
Balakrishnan Dhinakaran 6-Dec-11 0:00am    
ok Let me check and tell u
M.Narmatha 6-Dec-11 0:02am    
ok...Thank u....
Balakrishnan Dhinakaran 6-Dec-11 0:05am    
Can you able to share your code I want to know how you are connected to the database(using Code behind or GUI)..?

1 solution

Instead of adding total price in code behind you can give like this

SQL
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

ASP.NET
<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
 
Share this answer
 

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