Saving data from gridview to xml file

/ Published in: VB.NET
Save to your folder(s)

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

Copy this code and paste it in your HTML
  1. Protected Sub GridView1_RowCommand(sender As Object, e As GridViewCommandEventArgs)
  2. If e.CommandName = "save" Then
  3. Dim st As String = Server.MapPath("emp.xml")
  4. Dim ds As New DataSet()
  5. ds.ReadXml(st)
  6. Dim r As DataRow = ds.Tables(0).NewRow()
  7. r(0) = Convert.ToInt32(DirectCast(GridView1.FooterRow.FindControl("TextBox1"), TextBox).Text)
  8. r(1) = DirectCast(GridView1.FooterRow.FindControl("TextBox3"), TextBox).Text
  9. r(2) = DirectCast(GridView1.FooterRow.FindControl("TextBox5"), TextBox).Text
  10. r(3) = Convert.ToInt32(DirectCast(GridView1.FooterRow.FindControl("TextBox7"), TextBox).Text)
  11. ds.Tables(0).Rows.Add(r)
  12. ds.WriteXml(st)
  13. getxml()
  14. End If
  15. End Sub

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.