Click here to Skip to main content
15,904,288 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
XML
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
                onselectedindexchanged="GridView1_SelectedIndexChanged" Width="100%">
            <Columns>
                <asp:TemplateField HeaderText="Sr No" >
                <ItemTemplate>
                <asp:Label ID="lblSerial" runat="server"></asp:Label>
                </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField HeaderText="Description" DataField="Description"
                    ItemStyle-Width="50%" >
<ItemStyle Width="50%"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField HeaderText="Quantity" DataField="Quantity"
                    ItemStyle-Width="10%" >
<ItemStyle Width="10%"></ItemStyle>
                </asp:BoundField>
                <asp:TemplateField HeaderText="Rate Per Unit">
                    <ItemTemplate>
                        <asp:TextBox runat="server" Width="95%" ItemStyle-Width="15%" ID="txtRatePerUnit" OnTextChanged="txtRatePerUnit_TextChanged" AutoPostBack="true"></asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Total Amount">
                    <ItemTemplate>
                        <asp:Label runat="server" ID="lblTotalAmount"  ItemStyle-Width="15%"></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>

            </Columns>
            </asp:GridView>
Posted
Comments
pravin_kale 9-Nov-13 23:15pm    
In This code i have to calculate particular column total in his textchang event Sr No,Description,Quantity this prev database field
i have to do multiplication of Quantity and Rate Per Unit in txtRatePerUnit txtchange event answer show in lblTotalAmount
Pls Tel me Solution
What have you tried?

Thanks So much Giving me this good Solution
I am finding another code if anybody want this solution They Can Use My following code

protected void txtRatePerUnit_TextChanged(object sender, EventArgs e)
{
int ind = ((sender as TextBox).NamingContainer as GridViewRow).RowIndex;
int latInd = GridView1.Rows.Count;
Int64 cnt = 0;
TextBox txtRatePerUnit = (TextBox)GridView1.Rows[ind].Cells[3].FindControl("txtRatePerUnit");
// TextBox percentage = (TextBox)gVAppraisal.Rows[((sender as TextBox).NamingContainer as GridViewRow).RowIndex].Cells[2].FindControl("txtPercentage");
Label lblTotalAmount = (Label)GridView1.Rows[ind].Cells[4].FindControl("lblTotalAmount");
if ((txtRatePerUnit.Text.Equals(string.Empty)))
txtRatePerUnit.Text = "0";
lblTotalAmount.Text = (Int32.Parse(txtRatePerUnit.Text) * (Int32.Parse(GridView1.Rows[ind].Cells[2].Text))).ToString();

foreach (GridViewRow r in GridView1.Rows)
{
Label lbl = (Label)r.Cells[4].FindControl("lblTotalAmount");
if (!(lbl.Text.Equals(string.Empty)))
cnt += Convert.ToInt64(lbl.Text);
}
TextBox7.Text = cnt.ToString();


}
 
Share this answer
 
Comments
anurag19289 12-Nov-13 8:27am    
Kindly rate my answer and accept it if it helped you :)
i guess this is what you are looking for. Accept it as answer if it helped you

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Text;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            string strcon = ConfigurationManager.ConnectionStrings["ConnectionStringdb"].ConnectionString;
            using (SqlConnection con = new SqlConnection(strcon))
            {

                SqlCommand cmd = new SqlCommand("USP_datamanipulation", con);
                cmd.CommandType = CommandType.StoredProcedure;

                con.Open();
                GridView1.DataSource = cmd.ExecuteReader();
                GridView1.DataBind();
                con.Close();
            }


        }
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {


        for (int i = 0; i < GridView1.Rows.Count; i++)
        {

            GridView1.Rows[i].Cells[3].Text = Convert.ToString(Convert.ToDecimal(GridView1.Rows[i].Cells[1].Text) * Convert.ToDecimal(GridView1.Rows[i].Cells[2].Text));

        }

    }
}


id  quantity   priceperunit  total

1   5           0.25         1.25

2   10          2.25         22.50

3   15          2.15         32.25

4   20          2.25         45.50
 
Share this answer
 
v2
Comments
anurag19289 13-Nov-13 6:13am    
:)

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