列之间的数据网格操作 [英] datagrid operation between columns

查看:71
本文介绍了列之间的数据网格操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我得到的数据网格

+==========+==========+==========+==========+
| Product  |  Price   | quantity |   Total  |
+==========+==========+==========+==========+

所以我从MySQL数据库(表1)获得了产品和价格.然后用户在数量单元格中输入数字,然后程序计算总计(总计=价格*数量)并将其保存在表2中(在MySQL中).

so i got Product and Price from MySQL database (Table1). and user enter number in the quantity cell and the program calculat the Total (Total=Price*quantity) the save it in Table2 (in MySQL).

这是一个例子

+==========+==========+==========+==========+
| Product  |  Price   | quantity |   Total  |
+==========+==========+==========+==========+
|  AAAAA   |    30    |    2     |    60    |
+==========+==========+==========+==========+

更新

我添加像这样的CellEditEndding处理程序

I add CellEditEndding handler like this

private void Produit_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
    {
        DataTable dt = new DataTable();
        dt = ((DataView)Produit.ItemsSource).ToTable();
        foreach (DataRow row in dt.Rows)
        {
            row["total"] = (Convert.ToDouble(row["price"]) * Convert.ToDouble(row["quantity"]));
        }
        Produit.ItemsSource = dt.DefaultView;
    }

当我编辑数量单元格时,所有东西都归零.

when i edit a quantity cell every thing is return to 0.

注意:当我填充DataGrid时,我用zoros填充总量

NOTE: when I'm filling the DataGrid i Fill quantity an total with zoros

推荐答案

据我了解您的问题,您想请用户输入产品代码和数量,然后将价格和总价自动添加到.为此,您需要在data grid column这样的data grid column中添加Label field

As i understand your question, you want to ask that the user just enter the product code and quantity then the price and total-price automatically add to the data grid view. For that purpose you need to add Label field with the help of TemplateField in your data grid column Like this

      <Columns>
                    <asp:TemplateField>
                        <ItemTemplate>
                            <asp:Label ID="lblprice" runat="server"></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
 <asp:TemplateField>
                        <ItemTemplate>
                            <asp:Label ID="lblTotalPrice" runat="server"></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
    </Columns>

然后将标签访问服务器端

Then access the label to server side

Label lblprice= (Label)row.FindControl("lblprice");
Label lblTotalPrice= (Label)row.FindControl("lblTotalPrice");

现在只需将值分配给这些标签即可.

Now just assign the values to these labels.

这篇关于列之间的数据网格操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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