Hope it's OK to ask this here. I want to develop a web page similar to page Genres.aspx - but using a web service to get an xml file from another server, instead of SQL tables from a local one. For testing, I have the web service on line at another web site (call it website2) - in practice it will be on a server at work.
Rather than coming from SQL tables, the data will come from an xml file on website2. I have found that I can create a the web service - and access it and hence the xml file via a dataset - but my coding is getting messy - moreover, so far I have been able only to read and edit the data - but not update the file itself. I had thought what I am trying to do would be a fairly simple extension of what I had done in the book - but that's not been so. Nevertheless, I have gone back to the book example to try and re-start.
Two questions:
1. Up until now, I have bound the grid view to the dataset in the code-behind - but have not seen away to show that as the data source in the GridView smart tag - may be because the datasource does not lead to full Gridview functionality. Could you suggest a better way of declaring the data set - and also comment on how the dataset and web method could allow writing as well as reading?
Web method
Code:
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml
<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://example.com/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class transxml
Inherits System.Web.Services.WebService
<WebMethod()> Public Function GetXmlFile() As XmlNode
Dim doc As New XmlDocument()
doc.Load(Server.MapPath("Tester/test.xml"))
Return doc.DocumentElement
End Function
End Class
Datasorce declaration
Code:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ws As New BooksInfo.transxml()
Dim element As XmlElement = DirectCast(ws.GetXmlFile(), XmlElement)
Dim ds As New DataSet()
Dim xnr As New XmlNodeReader(element)
ds.ReadXml(xnr)
GridView1.DataSource = ds
GridView1.DataBind()
End Sub
[code]
Question 2.
When I do get the dataset sorted out - looking at the Genres.aspx example for reference - would it be sensible to replace
Code:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:PlanetWroxConnectionString1 %>" DeleteCommand="DELETE FROM [Genre] WHERE [Id] = @Id" InsertCommand="INSERT INTO [Genre] ([Name], [SortOrder]) VALUES (@Name, @SortOrder)" ProviderName="<%$ ConnectionStrings:PlanetWroxConnectionString1.ProviderName %>" SelectCommand="SELECT [Id], [Name], [SortOrder] FROM [Genre]" UpdateCommand="UPDATE [Genre] SET [Name] = @Name, [SortOrder] = @SortOrder WHERE [Id] = @Id">
with an XMLDataSource expression?