Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If (Not IsPostBack) Then
mygrid.DataSource = CreateDataSource()
mygrid.DataBind()
End If
End Sub
Private Function CreateDataSource() As DataSet
Dim mydata As XmlDataDocument = New XmlDataDocument
mydata.DataSet.ReadXml(Server.MapPath("magazzino.xml"))
Return mydata.DataSet
End Function
Public Sub doCancel(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
mygrid.EditItemIndex = -1
mygrid.DataSource = CreateDataSource()
mygrid.DataBind()
End Sub
Public Sub doEdit(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
mygrid.EditItemIndex = e.Item.ItemIndex
mygrid.DataSource = CreateDataSource()
mygrid.DataBind()
End Sub
Public Sub doUpdate(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
Dim nome As String = CType(e.Item.Cells(0).Controls(1), TextBox).Text
Dim quantita As String = CType(e.Item.Cells(1).Controls(1), TextBox).Text
mygrid.EditItemIndex = -1
Dim ds As DataSet = CreateDataSource()
Dim row As DataRow = ds.Tables(0).Rows(e.Item.ItemIndex)
row("nome") = nome
row("quantita") = quantita
ds.WriteXml(Server.MapPath("magazzino.xml"))
mygrid.DataSource = CreateDataSource()
mygrid.DataBind()
End Sub
Public Sub doDelete(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
mygrid.EditItemIndex = -1
Dim ds As DataSet = CreateDataSource()
Dim row As DataRow = ds.Tables(0).Rows(e.Item.ItemIndex)
row.Delete()
ds.WriteXml(Server.MapPath("magazzino.xml"))
mygrid.DataSource = CreateDataSource()
mygrid.DataBind()
End Sub