简体   繁体   English

如何在C#中的datagridview中动态添加行

[英]How to add dynamically row in datagridview in C#

How can I dynamically add a row in datagridview in c#. 如何在C#中的datagridview中动态添加一行。 Sum of cell and print total answer in the last row? 单元格总和并在最后一行打印总答案?

You want a footer row if I am correct. 如果我正确的话,你想要一个页脚行。 You must add a 您必须添加一个

<FooterTemplate> </FooterTemplate>

in your data grid. 在您的数据网格中。 Then you can use it in RowCreated, Page Unload events (or where you need) to modify contents and display desired data. 然后,您可以在RowCreated,Page Unload事件(或您需要的地方)中使用它来修改内容并显示所需的数据。

You could use RowCreated event as : 您可以将RowCreated事件用作:

protected void MyGrid_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Footer)
        {
            //e.Row.FindControl("what ever control i have");
            //use the control to modify content
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM