Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have Datagrid which hold Account Record of a Client
i want to add all values under Dues Column and show in TextBox....

C#
try
                {

                    SqlConnection conn = new SqlConnection("Server= localhost; database=tailoringmng; integrated Security=true");
                    SqlCommand cmd = new SqlCommand("spiaccount", conn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@id",cid);
                    cmd.Parameters.AddWithValue("@oid", oid);
                    SqlDataAdapter da = new SqlDataAdapter(cmd);

                    if (conn == null && conn.State == ConnectionState.Closed)
                    {
                        conn.Open();
                    }

                    dtableorder = new DataTable("myTable");
                    da.Fill(dtableorder);
                    
                    accountgrid.DataSource = dtableorder.DefaultView;

                    conn.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);

                }


and also want if someone change in the above grid values it must update in the Database.
Columns i have
Client Id
Order ID
CName
amountreceive
amountpaid
dues
Posted
Updated 14-Feb-14 17:10pm
v3
Comments
agent_kruger 14-Feb-14 23:16pm    
is dues column numeric?

Check these out:
1. TotalRow-DataGrid.aspx[^]
2. Using the DataGrid Control[^]
However, you may want to consider switching to DataGridView for winforms, read this:
http://msdn.microsoft.com/en-us/magazine/cc163933.aspx[^]
 
Share this answer
 
v2
I assume that it is a Web App,
C#
int total = 0;
protected void gvEmp_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if(e.Row.RowType==DataControlRowType.DataRow)
    {
        total += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Amount"));
    }
    if(e.Row.RowType==DataControlRowType.Footer)
    {
        Label lblamount = (Label)e.Row.FindControl("lblTotal");// instead use your textbox
        lblamount.Text = total.ToString();
    }
}
 
Share this answer
 
Comments
abdul manan 7 14-Feb-14 13:28pm    
Nice but i am using winform not webform
how to convert this your code to winform

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