.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Sandeep Singh

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

which gridview event i have to apply for my requirement

Posted By: srinivas     Posted Date: February 16, 2012    Points:5   Category :ASP.Net
hi , i have a gridview with columns like modelno,company,price,stock,quantity and totalprice.on runtime the database table values are binding to these columns.up to now there are no worries.now my requirement is i want to access only particular column of gridview.i.e quantity column.that which have to take the value i mentioned for ex 2 and it should multiply with the price column and result should dynamically bind to the total price column.
for ex modelno(product)price is 10,000 stock will represents how many pieces are available from database.here we are entering the value on quantity column.after entering the value it should perform an operation in code behind and dynamically bind to totalprice column.

for this to work what event i have to take in gridview,i took rowcommand for this.but the event is not firing.and what method i have to approach for dynamic binding method.thanks in adv.


<asp:GridView ID="gridcart" runat="server" AllowPaging="true"
AutoGenerateColumns="False" Width="584px"
<asp:TemplateField HeaderText="Model No" ItemStyle-HorizontalAlign="Center">
<asp:TemplateField HeaderText="Company" ItemStyle-HorizontalAlign="Center">
<asp:TemplateField HeaderText="Price" ItemStyle-HorizontalAlign="Center">
<ItemTemplate><asp:Label ID="lblprice" runat="server" Text='<%#Eval("PRICE")%>'/></ItemTemplate>
<asp:TemplateField HeaderText="Stock" ItemStyle-HorizontalAlign="Center">
<asp:TemplateField HeaderText="Quantity" ItemStyle-HorizontalAlign="Center">
<ItemTemplate><asp:TextBox ID="textquan" runat="server"/></ItemTemplate>
<asp:TemplateField HeaderText="TotalPrice" ItemStyle-HorizontalAlign="Center">
<ItemTemplate><asp:Label ID="lbltp" runat="server" ReadOnly="true"/></ItemTemplate>


protected void gridcart_RowCommand(object sender, GridViewCommandEventArgs e)

TextBox quantity = (TextBox)gridcart.FindControl("textquan");
int quan = Convert.ToInt32(quantity.Text);
Label price = (Label)gridcart.FindControl("lblprice");
int price1 = Convert.ToInt32(price.Text);
Label totalprice = (Label)gridcart.FindControl("lbltp");
int tp = Convert.ToInt32(totalprice.Text);
int abc = (price1) * (quan);
tp = abc;

Author: Amit Mehra             
Posted Date: February 17, 2012     Points: 20   


Do you have any button to updated total? If yes you can write code into button click event. If not and as far as I know gridview does not have any event to do so.

You can use JQuery to update the total as <TD> tag to show the updated total in UI

Hope this will give you an idea..

Please "Mark As Answer " if this post help you.
Author: srinivas             
Posted Date: February 18, 2012     Points: 20   

no worries,i sorted it out.. with textchanged event in textbox. thanks for your reply.

Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend