我如何从xml读取值并分配项目源 [英] How can i read values from xml and assign the itemssource

查看:52
本文介绍了我如何从xml读取值并分配项目源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在努力,

我将学生详细信息存储在isolatedstoragefile中,并读取isolatedstoragefile来分配数据网格项源.

我确实完成了存储并从isolatedstoragefile中检索了值

最后,iam获得了价值

字符串result =

 <?  xml  版本   1.0"   编码  ="  utf-8" > 
<  数据    ="   http://www.w3.org/2001/XMLSchema-instance"  xmlns:xsd    http://www.w3.org/2001/XMLSchema" <   StudentName  >  Raju <  /StudentName  > 
  <   RegNo  >  54 <  /RegNo  > 
  <   Marks1  >  65 <  /Marks1  > 
  <   Marks2  >  87 <  /Marks2  > 
  <   Marks3  >  88 <  /Marks3  > 
  <   Marks4  >  97 <  /Marks4  > 
<  /Data  >  


现在这样,我不知道如何从该字符串中读取学生详细信息并分配datagrid.itemssource = result.

让我知道如何阅读以绑定项目源

感谢和问候.........

解决方案

检查本文.

XML到DataSet或GridView并返回 [ ^ ]

最后我在谷歌搜索后做到了

 XDocument xmlProducts = XDocument.Parse(results);
                     var  student = 来自 xmlProducts中的 stu .后裔(" )
                                  选择 学生
                                  {
                                      StudentName = stu.Element(" ).值,
                                      RegNo = Convert.ToInt32(stu.Element(" ).Value),
                                      Marks1 = Convert.ToInt32(stu.Element(" ).Value),
                                      Marks2 = Convert.ToInt32(stu.Element(" ).Value),
                                      Marks3 = Convert.ToInt32(stu.Element(" ).Value),
                                      Marks4 = Convert.ToInt32(stu.Element(" ).Value)
                                  };
                    dataGrid4.ItemsSource =学生; 


hi all,

iam working the silverlight,

i am store the student details in isolatedstoragefile and read the isolatedstoragefile to assign the datagrid itemssource.

i did complete the store and retrive the values from isolatedstoragefile

lastly iam getting the value

string result=

<?xml version="1.0" encoding="utf-8"?>
<Data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <StudentName>Raju</StudentName>
  <RegNo>54</RegNo>
  <Marks1>65</Marks1>
  <Marks2>87</Marks2>
  <Marks3>88</Marks3>
  <Marks4>97</Marks4>
</Data>


like this now i don''t know how can i read the student details from this string and assign the datagrid.itemssource=result.

let me know how to read to bind the itemssource

thanks and regards.........

解决方案

Check this article.

XML to DataSet or GridView and back[^]


finally i did this after googling

XDocument xmlProducts = XDocument.Parse(results);
                    var student = from stu in xmlProducts.Descendants("Students")
                                  select new Students
                                  {
                                      StudentName = stu.Element("StudentName").Value,
                                      RegNo = Convert.ToInt32(stu.Element("RegNo").Value),
                                      Marks1 = Convert.ToInt32(stu.Element("Marks1").Value),
                                      Marks2 = Convert.ToInt32(stu.Element("Marks1").Value),
                                      Marks3 = Convert.ToInt32(stu.Element("Marks1").Value),
                                      Marks4 = Convert.ToInt32(stu.Element("Marks1").Value)
                                  };
                    dataGrid4.ItemsSource = student;


这篇关于我如何从xml读取值并分配项目源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆