如何将VB中GridView控件中的更新保存到现有XML文档?

如何将VB中GridView控件中的更新保存到现有XML文档?,xml,vb.net,soap,Xml,Vb.net,Soap,我有一个包含音乐播放列表信息的现有xml文档,它被读入Visual Basic中的GridView控件。我现在想将GridView中的任何更新保存到该xml文档中。我该怎么做 Private Sub cboUsers_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboUsers.SelectedIndexChanged Dim songList As Ne

我有一个包含音乐播放列表信息的现有xml文档,它被读入Visual Basic中的GridView控件。我现在想将GridView中的任何更新保存到该xml文档中。我该怎么做

Private Sub cboUsers_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboUsers.SelectedIndexChanged
    Dim songList As New XmlDocument
    songList.LoadXml(s.GetPlaylist(cboUsers.SelectedItem.ToString()))
    Grid.Rows.Clear()
    Dim songs As XmlNodeList = songList.DocumentElement.SelectNodes("//Song")
    Dim song As XmlNode
    For Each song In songs
        Dim artist As String = song.SelectSingleNode("artist").InnerText
        Dim title As String = song.SelectSingleNode("title").InnerText
        Dim length As String = song.SelectSingleNode("length").InnerText
        Dim album As String = song.SelectSingleNode("album").InnerText
        Dim popularity As String = song.SelectSingleNode("popularity").InnerText
        Dim row() As Object = {artist, title, length, album, popularity}
        Grid.Rows.Add(row) ' Add as a row in the Grid
    Next
End Sub

谢谢

一种方法是添加您自己的更新命令列

<asp:CommandField ShowEditButton="True" HeaderStyle-Width="80px" />
乙二醇

对XML进行更新,然后取消更新本身

 e.Cancel = true;
C代码示例,但很容易复制到VB

编辑,根据要求添加VB代码

Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating

    'Get some new values
    Dim foo As String = e.NewValues("fooColumn").ToString()

    'Im not sure how you plan to find the unique XML node so lets assume that your using title

    'So either get it from a datakey, if your using them in the gridview
    Dim titleFromDataKey As String = GridView1.DataKeys(e.RowIndex)("Title").ToString();

    'Or from the old values
    Dim titleFromOldValues = e.OldValues("Title").ToString()

    'Insert your logic to find the XML node and update it here

    'Cancel the update
    e.Cancel = True

End Sub

我不熟悉C,所以对我来说复制到VB不是那么容易…你能提供一个VB的例子吗?
 e.Cancel = true;
Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating

    'Get some new values
    Dim foo As String = e.NewValues("fooColumn").ToString()

    'Im not sure how you plan to find the unique XML node so lets assume that your using title

    'So either get it from a datakey, if your using them in the gridview
    Dim titleFromDataKey As String = GridView1.DataKeys(e.RowIndex)("Title").ToString();

    'Or from the old values
    Dim titleFromOldValues = e.OldValues("Title").ToString()

    'Insert your logic to find the XML node and update it here

    'Cancel the update
    e.Cancel = True

End Sub