如何添加Datagrid列的值? [英] How to add up values of Datagrid Column?

查看:91
本文介绍了如何添加Datagrid列的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Datagrid持有客户的账户记录

i想要在Dues列下添加所有值并在TextBox中显示....



i have Datagrid which hold Account Record of a Client
i want to add all values under Dues Column and show in TextBox....

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);

                }





并且如果有人更改了上面的网格值,它也必须在数据库中更新。

列我有

客户ID

订单ID

CName

amountreceive < br $>
amountpaid

dues



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

推荐答案

查看这些:

1. TotalRow-DataGrid.aspx [ ^ ]

2. 使用DataGrid控件 [ ^ ]

但是,您可能需要考虑切换到DataGridView for winforms,请阅读:

http://msdn.microsoft.com /en-us/magazine/cc163933.aspx [ ^ ]
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[^]


我认为它是一个Web应用程序,

I assume that it is a Web App,
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();
    }
}


这篇关于如何添加Datagrid列的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆