如何显示数据从xml Gridview linq到xml c#
本文关键字:xml Gridview linq 数据 何显示 显示 | 更新日期: 2023-09-27 18:08:14
我想显示为Gridview,以便导出到excel电子表格,而不是将此代码编写到控制台。我在VStudio和代码中做了哪些设置和设置。我是相当新的c#编程,请帮助。
class Program
{
public class XAxisCalib
{
public int Max1 { get; set; }
public int Min2 { get; set; }
public int Max3 { get; set; }
public int Min4 { get; set; }
public int Max5 { get; set; }
public int Min6 { get; set; }
}
static void Main(string[] args)
{
string[] fileEntries = Directory.GetFiles(@"c:'Sciclone UAC", "*.cfg*");
foreach (string fileName in fileEntries)
{
{
XDocument doc = XDocument.Load(fileName);
var query = from x in doc.Descendants("XAxisCalib")
select new
{
MaxChild = x.Descendants("Max"),
MinChild = x.Descendants("Min")
};
foreach (var x in query)
{
foreach (var nextLevel in x.MaxChild)
{
Console.WriteLine("" + nextLevel.Value);
}
foreach (var nextLevel in x.MinChild)
{
Console.WriteLine("" + nextLevel.Value + "'n");
}
}
var query2 = from y in doc.Descendants("YAxisCalib")
select new
{
MaxChild = y.Descendants("Max"),
MinChild = y.Descendants("Min")
};
foreach (var y in query2)
{
foreach (var nextLevel in y.MaxChild)
{
Console.WriteLine("" + nextLevel.Value);
}
foreach (var nextLevel in y.MinChild)
{
Console.WriteLine("" + nextLevel.Value + "'n");
}
var query3 = from z in doc.Descendants("ZAxisCalib")
select new
{
MaxChild = z.Descendants("Max"),
MinChild = z.Descendants("Min")
};
foreach (var z in query3)
{
foreach (var nextLevel in z.MaxChild)
{
Console.WriteLine("" + nextLevel.Value);
}
foreach (var nextLevel in z.MinChild)
{
Console.WriteLine("" + nextLevel.Value + "'n");
}
}
}
}
}
}
}
}
我认为最快的方法是将XML加载到数据集中,并将其用作GridView的数据源。
更多信息请看:
http://msdn.microsoft.com/en-us/library/fx29c3yd.aspx