Hi all,
I am working on linking a XML file to a datagrid. I have enabled the datagrid to display the contents of the xml file using the datagrid.
But I want to be able to do more that to just display the content, I also want to be able to add new rows, edit existing rows, and delete existing rows. I am doing all this through the datagrid's edit,update,and delete feature.
Currently, I am working on the "insert_new_row" function and am able to insert a new row, but can not get a value into the new row. Instead, I get something like this...
<word xsi:nil="true" />
Here is the entry added to my original xml document...
<?xml version="1.0" standalone="yes"?>
<root xmlns:xsi=" <words>
<word>value1</word>
<word>value2</word>
<word>value3</word>
<word>etc</word>
</words>
<word xsi:nil="true" />
</root>
I have tried many thing but cannot get the the row to be <word>newword</word>
Here is my code...
Sub LoadXML()
Dim objdata As New DataSet
Try
objdata.ReadXml(MapPath("Words.xml"))
DataGrid1.DataSource = objdata
DataGrid1.DataMember = "word"
DataGrid1.DataBind()
Catch exc As Exception
ProcessModuleLoadException(Me, exc)
End Try
End Sub
Sub insert_new_row(ByVal Sender As Object, ByVal E As DataGridCommandEventArgs)
Try
If E.CommandName = "doAdd" Then
Dim objdata As New DataSet
Dim tadd1 As TextBox
Dim dr As DataRow
objdata.ReadXml(MapPath("Words.xml")) 'fill in dataset
tadd1 = E.Item.FindControl("word_add_txt")
objdata.Tables("word").DefaultView.RowFilter = ""
dr = objdata.Tables("word").NewRow()
'dr(0) = tadd1.Text --- I am trying to assign the value "newword" here but i get an error, so I commented it out and now get my current output.
objdata.Tables("word").Rows.Add(dr)
objdata.WriteXml(MapPath("Words.xml"))
LoadXML()
End If
Catch exc As Exception
ProcessModuleLoadException(Me, exc)
End Try
End Sub
Any suggestion will help. Thank you in advance.
-a8le
I am working on linking a XML file to a datagrid. I have enabled the datagrid to display the contents of the xml file using the datagrid.
But I want to be able to do more that to just display the content, I also want to be able to add new rows, edit existing rows, and delete existing rows. I am doing all this through the datagrid's edit,update,and delete feature.
Currently, I am working on the "insert_new_row" function and am able to insert a new row, but can not get a value into the new row. Instead, I get something like this...
<word xsi:nil="true" />
Here is the entry added to my original xml document...
<?xml version="1.0" standalone="yes"?>
<root xmlns:xsi=" <words>
<word>value1</word>
<word>value2</word>
<word>value3</word>
<word>etc</word>
</words>
<word xsi:nil="true" />
</root>
I have tried many thing but cannot get the the row to be <word>newword</word>
Here is my code...
Sub LoadXML()
Dim objdata As New DataSet
Try
objdata.ReadXml(MapPath("Words.xml"))
DataGrid1.DataSource = objdata
DataGrid1.DataMember = "word"
DataGrid1.DataBind()
Catch exc As Exception
ProcessModuleLoadException(Me, exc)
End Try
End Sub
Sub insert_new_row(ByVal Sender As Object, ByVal E As DataGridCommandEventArgs)
Try
If E.CommandName = "doAdd" Then
Dim objdata As New DataSet
Dim tadd1 As TextBox
Dim dr As DataRow
objdata.ReadXml(MapPath("Words.xml")) 'fill in dataset
tadd1 = E.Item.FindControl("word_add_txt")
objdata.Tables("word").DefaultView.RowFilter = ""
dr = objdata.Tables("word").NewRow()
'dr(0) = tadd1.Text --- I am trying to assign the value "newword" here but i get an error, so I commented it out and now get my current output.
objdata.Tables("word").Rows.Add(dr)
objdata.WriteXml(MapPath("Words.xml"))
LoadXML()
End If
Catch exc As Exception
ProcessModuleLoadException(Me, exc)
End Try
End Sub
Any suggestion will help. Thank you in advance.
-a8le