I want to display an xml file data in silverlight datagrid. im using the below code but it doesnt work.Please help.
My vb.net code:
Imports System Imports System.Collections.Generic Imports System.Linq Imports System.Windows Imports System.Windows.Contr开发者_StackOverflow中文版ols Imports System.Xml.Linq
Namespace SilverlightApplication1 Public Partial Class Page Inherits UserControl Public Sub New() InitializeComponent() End Sub
Private Sub Page_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
DataGrid1.ItemsSource = GetReport()
End Sub
Public Function GetStatusReport() As List(Of Table)
Dim statusReport As New List(Of Table)()
Dim doc As XElement = XElement.Load("Data/Report.xml")
report = (From row In doc.Elements() _
Select GetStatus(row)).ToList()
Return statusReport
End Function
Private Function GetReport(ByVal row As XElement) As Table
Dim s As New Table()
s.JobID= row.Attribute("ID").Value
s.VenueName= row.Attribute("Name").Value)
Return s
End Function
End Class
End Namespace
I am so confused by this code... which is probably why it is not working.
First, when you set the ItemsSource, you call GetReport() without a parameter. GetStatusReport() is never called, even though it does the XML lifting. Inside of GetStatusReport, you return statusReport, which is an empty list... and you never do anything with report, which is the actual query. Inside the query, you call GetStatus, which is not defined, though I believe it should be GetReport.
Arghhh... with all that, I would guess that you want to re-write all that code to be something like this:
Private Sub Page_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
DataGrid1.ItemsSource = GetStatusReport()
End Sub
Public Function GetStatusReport() As List(Of Table)
Dim statusReport As New List(Of Table)()
Dim doc As XElement = XElement.Load("Data/Report.xml")
statusReport = (From row In doc.Elements() _
Select GetReport(row)).ToList()
Return statusReport
End Function
Private Function GetReport(ByVal row As XElement) As Table
Dim s As New Table()
s.JobID= row.Attribute("ID").Value
s.VenueName= row.Attribute("Name").Value)
Return s
End Function
End Class
Beyond those fixes, I can't tell you if it is correct or not... Where is it failing?
精彩评论