datagrid查看数据到xml [英] datagrid view data to xml

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

问题描述

我只想将所有数据从datagridview发送到xml



i just want to send all data from datagridview to xml



StringBuilder strB = new StringBuilder();
    //create html & table
    strB.AppendLine("<html><body><center><table border='1' cellpadding='0' cellspacing='0'>");
    strB.AppendLine("<tr>");
    //cteate table header
    for (int i = 0; i < dg.Columns.Count; i++)

    {

        strB.AppendLine("<td align='center' valign='middle'>" + dg.Columns[i].HeaderText + "</td>");
    }
    //create table body
    strB.AppendLine("<tr>");
    for (int i = 0; i < dg.Rows.Count; i++)

    {

        strB.AppendLine("<tr>");
        foreach (DataGridViewCell dgvc in dg.Rows[i].Cells)
        {
            strB.AppendLine("<td align='center' valign='middle'>" + dgvc.Value.ToString() + "</td>");
        }
        strB.AppendLine("</tr>");

    }
    //table footer & end of html file
    strB.AppendLine("</table></center></body></html>");
    return strB;
}

推荐答案

datasetObj.WriteXml(nameOfXml);



或了解更多信息,请访问下面的链接
链接1
Link2
Link3

希望对您有帮助....



or for more info visit below link
Link1
Link2
Link3

hope it will help you....


如果您的DataGridView绑定到数据,则可以使用DataSource.WriteXML方法.
如果不是,那么您将不得不手动循环遍历这些行,或者将它们动态转换为XML,或者从中创建一个新的XML感知对象.我建议编写一个通用例程以从DataGridView.Rows集合创建DataTable将是最灵活的-而且DataTable可以识别XML,因此它具有WriteXML方法.
If your DataGridView is bound to data, then you can use the DataSource.WriteXML method.
If it isn''t, then you will have to manually loop through the rows, either converting them to XML on the fly, or creating a new XML-aware object from it. I would suggest that writing a generic routine to create a DataTable from the DataGridView.Rows collection would be the most flexible - and DataTable is XML aware, so it has a WriteXML method.


这篇关于datagrid查看数据到xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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