Saving data from gridview to xml file

Submitted by:Jhon Jhon

Date added:21 January, 2013

Category:VB.NET

This code will show you how to save data from gridview to xml file

Tags: gridview to xml

Code Snippet:

    Protected Sub GridView1_RowCommand(sender As Object, e As GridViewCommandEventArgs)
If e.CommandName = "save" Then
Dim st As String = Server.MapPath("emp.xml")
Dim ds As New DataSet()
ds.ReadXml(st)
Dim r As DataRow = ds.Tables(0).NewRow()
r(0) = Convert.ToInt32(DirectCast(GridView1.FooterRow.FindControl("TextBox1"), TextBox).Text)
r(1) = DirectCast(GridView1.FooterRow.FindControl("TextBox3"), TextBox).Text
r(2) = DirectCast(GridView1.FooterRow.FindControl("TextBox5"), TextBox).Text
r(3) = Convert.ToInt32(DirectCast(GridView1.FooterRow.FindControl("TextBox7"), TextBox).Text)
ds.Tables(0).Rows.Add(r)
ds.WriteXml(st)
getxml()
End If
End Sub
 
 

Comments