简体   繁体   中英

How to add dynamically row in datagridview in C#

How can I dynamically add a row in datagridview in c#. 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.

You could use RowCreated event as :

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
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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