Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i just want to send all data from datagridview to xml



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;
}
Posted
Updated 11-Aug-11 22:11pm
v2
Comments
Herman<T>.Instance 12-Aug-11 3:58am    
what have you tried?
Al Moje 12-Aug-11 4:06am    
Could you see us your code you've been try.

datasetObj.WriteXml(nameOfXml);


or for more info visit below link
Link1
Link2
Link3

hope it will help you....
 
Share this answer
 
v2
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900