DataGrideView DataTable XML

           DataTable dt = new DataTable();
            foreach (DataGridViewColumn headerCell in dataGridView1.Columns)
            {
                dt.Columns.Add(headerCell.HeaderText);
            }
            foreach (DataGridViewRow item in dataGridView1.Rows)
            {
                DataRow dr = dt.NewRow();
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    dr[0] = item.Cells[i].Value.ToString();
                }
                dt.Rows.Add(dr);
            }
            dt.WriteXml("data.xml");

posted @ 2010-01-22 12:17  greencolor  阅读(137)  评论(0编辑  收藏  举报