在 Gridview 中显示 LINQ TO XML 查询的结果

发布于 2024-08-02 19:47:50 字数 6928 浏览 3 评论 0原文

我正在 LINQ 中查询 xml 文档,并希望在 gridview 中显示结果以允许用户从列表中进行选择。

查询是用户输入的结果。

这是我的 xml 的副本。

<?xml version="1.0" standalone="yes"?>
<NewDataSet>
  <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:msprop="urn:schemas-microsoft-com:xml-msprop">
    <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
      <xs:complexType>
        <xs:choice minOccurs="0" maxOccurs="unbounded">
          <xs:element name="Table">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="ROOM_ID" msprop:OraDbType="111" type="xs:short" minOccurs="0" />
                <xs:element name="SMOKING" msprop:OraDbType="126" type="xs:string" minOccurs="0" />
                <xs:element name="NO_OF_PEOPLE" msprop:OraDbType="111" type="xs:short" minOccurs="0" />
                <xs:element name="ROOM_COST" msprop:OraDbType="108" type="xs:double" minOccurs="0" />
                <xs:element name="ROOM_TYPE" msprop:OraDbType="126" type="xs:string" minOccurs="0" />
                <xs:element name="ROOM_DESC" msprop:OraDbType="126" type="xs:string" minOccurs="0" />
                <xs:element name="BOOKING_ID" msprop:OraDbType="111" type="xs:short" minOccurs="0" />
                <xs:element name="DATE_FROM" msprop:OraDbType="106" type="xs:dateTime" minOccurs="0" />
                <xs:element name="DATE_TO" msprop:OraDbType="106" type="xs:dateTime" minOccurs="0" />
                <xs:element name="HOTEL_AREA" msprop:OraDbType="126" type="xs:string" minOccurs="0" />
                <xs:element name="HOTEL_NAME" msprop:OraDbType="126" type="xs:string" minOccurs="0" />
                <xs:element name="RESTAURANT" msprop:OraDbType="126" type="xs:string" minOccurs="0" />
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:choice>
      </xs:complexType>
    </xs:element>
  </xs:schema>
  <Table>
    <ROOM_ID>101</ROOM_ID>
    <SMOKING>N</SMOKING>
    <NO_OF_PEOPLE>1</NO_OF_PEOPLE>
    <ROOM_COST>29.990000000000002</ROOM_COST>
    <ROOM_TYPE>SINGLE ROOM</ROOM_TYPE>
    <ROOM_DESC>ONE BED, MIRROR, DESK, COUCH</ROOM_DESC>
    <BOOKING_ID>300</BOOKING_ID>
    <DATE_FROM>2008-01-02T00:00:00+00:00</DATE_FROM>
    <DATE_TO>2008-01-04T00:00:00+00:00</DATE_TO>
    <HOTEL_AREA>WOLVERHAMPTON</HOTEL_AREA>
    <HOTEL_NAME>LEVELS</HOTEL_NAME>
    <RESTAURANT>N</RESTAURANT>
  </Table>
  <Table>
    <ROOM_ID>105</ROOM_ID>
    <SMOKING>Y</SMOKING>
    <NO_OF_PEOPLE>4</NO_OF_PEOPLE>
    <ROOM_COST>59.99</ROOM_COST>
    <ROOM_TYPE>EN-SUITE</ROOM_TYPE>
    <ROOM_DESC>KINGSIZE BED, MIRROR, GARDEN</ROOM_DESC>
    <BOOKING_ID>301</BOOKING_ID>
    <DATE_FROM>2009-01-02T00:00:00+00:00</DATE_FROM>
    <DATE_TO>2009-01-15T00:00:00+00:00</DATE_TO>
    <HOTEL_AREA>STAFFORD</HOTEL_AREA>
    <HOTEL_NAME>HILTON</HOTEL_NAME>
    <RESTAURANT>Y</RESTAURANT>
  </Table>
  <Table>
    <ROOM_ID>111</ROOM_ID>
    <SMOKING>N</SMOKING>
    <NO_OF_PEOPLE>10</NO_OF_PEOPLE>
    <ROOM_COST>49.99</ROOM_COST>
    <ROOM_TYPE>HOSTEL ROOM</ROOM_TYPE>
    <ROOM_DESC>DOUBLE-DECKER BED, DRAWER</ROOM_DESC>
    <BOOKING_ID>302</BOOKING_ID>
    <DATE_FROM>2009-03-02T00:00:00+00:00</DATE_FROM>
    <DATE_TO>2009-06-15T00:00:00+01:00</DATE_TO>
    <HOTEL_AREA>WOLVERHAMPTON</HOTEL_AREA>
    <HOTEL_NAME>LEVELS</HOTEL_NAME>
    <RESTAURANT>N</RESTAURANT>
  </Table>
  <Table>
    <ROOM_ID>113</ROOM_ID>
    <SMOKING>N</SMOKING>
    <NO_OF_PEOPLE>1</NO_OF_PEOPLE>
    <ROOM_COST>29.990000000000002</ROOM_COST>
    <ROOM_TYPE>SINGLE ROOM</ROOM_TYPE>
    <ROOM_DESC>ONE BED, MIRROR, DESK, COUCH</ROOM_DESC>
    <BOOKING_ID>303</BOOKING_ID>
    <DATE_FROM>2009-09-02T00:00:00+01:00</DATE_FROM>
    <DATE_TO>2009-09-05T00:00:00+01:00</DATE_TO>
    <HOTEL_AREA>BASWICH</HOTEL_AREA>
    <HOTEL_NAME>DAYSTAR</HOTEL_NAME>
    <RESTAURANT>Y</RESTAURANT>
  </Table>
  <Table>
    <ROOM_ID>103</ROOM_ID>
    <SMOKING>Y</SMOKING>
    <NO_OF_PEOPLE>2</NO_OF_PEOPLE>
    <ROOM_COST>39.99</ROOM_COST>
    <ROOM_TYPE>DOUBLE ROOM</ROOM_TYPE>
    <ROOM_DESC>DOUBLE BED, MIRROR, SEETEE</ROOM_DESC>
    <BOOKING_ID>304</BOOKING_ID>
    <DATE_FROM>2009-08-21T00:00:00+01:00</DATE_FROM>
    <DATE_TO>2009-08-25T00:00:00+01:00</DATE_TO>
    <HOTEL_AREA>CANNOCK</HOTEL_AREA>
    <HOTEL_NAME>MIDAS</HOTEL_NAME>
    <RESTAURANT>N</RESTAURANT>
  </Table>
  <Table>
    <ROOM_ID>107</ROOM_ID>
    <SMOKING>Y</SMOKING>
    <NO_OF_PEOPLE>10</NO_OF_PEOPLE>
    <ROOM_COST>49.99</ROOM_COST>
    <ROOM_TYPE>HOSTEL ROOM</ROOM_TYPE>
    <ROOM_DESC>DOUBLE-DECKER BED, DRAWER</ROOM_DESC>
    <BOOKING_ID>305</BOOKING_ID>
    <DATE_FROM>2009-08-25T00:00:00+01:00</DATE_FROM>
    <DATE_TO>2009-08-31T00:00:00+01:00</DATE_TO>
    <HOTEL_AREA>STOKE</HOTEL_AREA>
    <HOTEL_NAME>MIVI</HOTEL_NAME>
    <RESTAURANT>Y</RESTAURANT>
  </Table>
  <Table>
    <ROOM_ID>141</ROOM_ID>
    <SMOKING>N</SMOKING>
    <NO_OF_PEOPLE>2</NO_OF_PEOPLE>
    <ROOM_COST>39.99</ROOM_COST>
    <ROOM_TYPE>DOUBLE ROOM</ROOM_TYPE>
    <ROOM_DESC>DOUBLE BED, MIRROR, SEETEE</ROOM_DESC>
    <HOTEL_AREA>BASWICH</HOTEL_AREA>
    <HOTEL_NAME>DAYSTAR</HOTEL_NAME>
    <RESTAURANT>Y</RESTAURANT>
  </Table>
  <Table>
    <ROOM_ID>109</ROOM_ID>
    <SMOKING>Y</SMOKING>
    <NO_OF_PEOPLE>1</NO_OF_PEOPLE>
    <ROOM_COST>19.990000000000002</ROOM_COST>
    <ROOM_TYPE>BED-SIT</ROOM_TYPE>
    <ROOM_DESC>ONE BED, DESK</ROOM_DESC>
    <HOTEL_AREA>CANNOCK</HOTEL_AREA>
    <HOTEL_NAME>MIDAS</HOTEL_NAME>
    <RESTAURANT>N</RESTAURANT>
  </Table>
</NewDataSet>

I am querying an xml document in LINQ and would want to display the results in gridview to allow users to select from the list.

the query is as a result of user input.

Here's a copy of my xml.

<?xml version="1.0" standalone="yes"?>
<NewDataSet>
  <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:msprop="urn:schemas-microsoft-com:xml-msprop">
    <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
      <xs:complexType>
        <xs:choice minOccurs="0" maxOccurs="unbounded">
          <xs:element name="Table">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="ROOM_ID" msprop:OraDbType="111" type="xs:short" minOccurs="0" />
                <xs:element name="SMOKING" msprop:OraDbType="126" type="xs:string" minOccurs="0" />
                <xs:element name="NO_OF_PEOPLE" msprop:OraDbType="111" type="xs:short" minOccurs="0" />
                <xs:element name="ROOM_COST" msprop:OraDbType="108" type="xs:double" minOccurs="0" />
                <xs:element name="ROOM_TYPE" msprop:OraDbType="126" type="xs:string" minOccurs="0" />
                <xs:element name="ROOM_DESC" msprop:OraDbType="126" type="xs:string" minOccurs="0" />
                <xs:element name="BOOKING_ID" msprop:OraDbType="111" type="xs:short" minOccurs="0" />
                <xs:element name="DATE_FROM" msprop:OraDbType="106" type="xs:dateTime" minOccurs="0" />
                <xs:element name="DATE_TO" msprop:OraDbType="106" type="xs:dateTime" minOccurs="0" />
                <xs:element name="HOTEL_AREA" msprop:OraDbType="126" type="xs:string" minOccurs="0" />
                <xs:element name="HOTEL_NAME" msprop:OraDbType="126" type="xs:string" minOccurs="0" />
                <xs:element name="RESTAURANT" msprop:OraDbType="126" type="xs:string" minOccurs="0" />
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:choice>
      </xs:complexType>
    </xs:element>
  </xs:schema>
  <Table>
    <ROOM_ID>101</ROOM_ID>
    <SMOKING>N</SMOKING>
    <NO_OF_PEOPLE>1</NO_OF_PEOPLE>
    <ROOM_COST>29.990000000000002</ROOM_COST>
    <ROOM_TYPE>SINGLE ROOM</ROOM_TYPE>
    <ROOM_DESC>ONE BED, MIRROR, DESK, COUCH</ROOM_DESC>
    <BOOKING_ID>300</BOOKING_ID>
    <DATE_FROM>2008-01-02T00:00:00+00:00</DATE_FROM>
    <DATE_TO>2008-01-04T00:00:00+00:00</DATE_TO>
    <HOTEL_AREA>WOLVERHAMPTON</HOTEL_AREA>
    <HOTEL_NAME>LEVELS</HOTEL_NAME>
    <RESTAURANT>N</RESTAURANT>
  </Table>
  <Table>
    <ROOM_ID>105</ROOM_ID>
    <SMOKING>Y</SMOKING>
    <NO_OF_PEOPLE>4</NO_OF_PEOPLE>
    <ROOM_COST>59.99</ROOM_COST>
    <ROOM_TYPE>EN-SUITE</ROOM_TYPE>
    <ROOM_DESC>KINGSIZE BED, MIRROR, GARDEN</ROOM_DESC>
    <BOOKING_ID>301</BOOKING_ID>
    <DATE_FROM>2009-01-02T00:00:00+00:00</DATE_FROM>
    <DATE_TO>2009-01-15T00:00:00+00:00</DATE_TO>
    <HOTEL_AREA>STAFFORD</HOTEL_AREA>
    <HOTEL_NAME>HILTON</HOTEL_NAME>
    <RESTAURANT>Y</RESTAURANT>
  </Table>
  <Table>
    <ROOM_ID>111</ROOM_ID>
    <SMOKING>N</SMOKING>
    <NO_OF_PEOPLE>10</NO_OF_PEOPLE>
    <ROOM_COST>49.99</ROOM_COST>
    <ROOM_TYPE>HOSTEL ROOM</ROOM_TYPE>
    <ROOM_DESC>DOUBLE-DECKER BED, DRAWER</ROOM_DESC>
    <BOOKING_ID>302</BOOKING_ID>
    <DATE_FROM>2009-03-02T00:00:00+00:00</DATE_FROM>
    <DATE_TO>2009-06-15T00:00:00+01:00</DATE_TO>
    <HOTEL_AREA>WOLVERHAMPTON</HOTEL_AREA>
    <HOTEL_NAME>LEVELS</HOTEL_NAME>
    <RESTAURANT>N</RESTAURANT>
  </Table>
  <Table>
    <ROOM_ID>113</ROOM_ID>
    <SMOKING>N</SMOKING>
    <NO_OF_PEOPLE>1</NO_OF_PEOPLE>
    <ROOM_COST>29.990000000000002</ROOM_COST>
    <ROOM_TYPE>SINGLE ROOM</ROOM_TYPE>
    <ROOM_DESC>ONE BED, MIRROR, DESK, COUCH</ROOM_DESC>
    <BOOKING_ID>303</BOOKING_ID>
    <DATE_FROM>2009-09-02T00:00:00+01:00</DATE_FROM>
    <DATE_TO>2009-09-05T00:00:00+01:00</DATE_TO>
    <HOTEL_AREA>BASWICH</HOTEL_AREA>
    <HOTEL_NAME>DAYSTAR</HOTEL_NAME>
    <RESTAURANT>Y</RESTAURANT>
  </Table>
  <Table>
    <ROOM_ID>103</ROOM_ID>
    <SMOKING>Y</SMOKING>
    <NO_OF_PEOPLE>2</NO_OF_PEOPLE>
    <ROOM_COST>39.99</ROOM_COST>
    <ROOM_TYPE>DOUBLE ROOM</ROOM_TYPE>
    <ROOM_DESC>DOUBLE BED, MIRROR, SEETEE</ROOM_DESC>
    <BOOKING_ID>304</BOOKING_ID>
    <DATE_FROM>2009-08-21T00:00:00+01:00</DATE_FROM>
    <DATE_TO>2009-08-25T00:00:00+01:00</DATE_TO>
    <HOTEL_AREA>CANNOCK</HOTEL_AREA>
    <HOTEL_NAME>MIDAS</HOTEL_NAME>
    <RESTAURANT>N</RESTAURANT>
  </Table>
  <Table>
    <ROOM_ID>107</ROOM_ID>
    <SMOKING>Y</SMOKING>
    <NO_OF_PEOPLE>10</NO_OF_PEOPLE>
    <ROOM_COST>49.99</ROOM_COST>
    <ROOM_TYPE>HOSTEL ROOM</ROOM_TYPE>
    <ROOM_DESC>DOUBLE-DECKER BED, DRAWER</ROOM_DESC>
    <BOOKING_ID>305</BOOKING_ID>
    <DATE_FROM>2009-08-25T00:00:00+01:00</DATE_FROM>
    <DATE_TO>2009-08-31T00:00:00+01:00</DATE_TO>
    <HOTEL_AREA>STOKE</HOTEL_AREA>
    <HOTEL_NAME>MIVI</HOTEL_NAME>
    <RESTAURANT>Y</RESTAURANT>
  </Table>
  <Table>
    <ROOM_ID>141</ROOM_ID>
    <SMOKING>N</SMOKING>
    <NO_OF_PEOPLE>2</NO_OF_PEOPLE>
    <ROOM_COST>39.99</ROOM_COST>
    <ROOM_TYPE>DOUBLE ROOM</ROOM_TYPE>
    <ROOM_DESC>DOUBLE BED, MIRROR, SEETEE</ROOM_DESC>
    <HOTEL_AREA>BASWICH</HOTEL_AREA>
    <HOTEL_NAME>DAYSTAR</HOTEL_NAME>
    <RESTAURANT>Y</RESTAURANT>
  </Table>
  <Table>
    <ROOM_ID>109</ROOM_ID>
    <SMOKING>Y</SMOKING>
    <NO_OF_PEOPLE>1</NO_OF_PEOPLE>
    <ROOM_COST>19.990000000000002</ROOM_COST>
    <ROOM_TYPE>BED-SIT</ROOM_TYPE>
    <ROOM_DESC>ONE BED, DESK</ROOM_DESC>
    <HOTEL_AREA>CANNOCK</HOTEL_AREA>
    <HOTEL_NAME>MIDAS</HOTEL_NAME>
    <RESTAURANT>N</RESTAURANT>
  </Table>
</NewDataSet>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半﹌身腐败 2024-08-09 19:47:50

你应该能够做到这一点。以下是一些示例:

http ://social.msdn.microsoft.com/Forums/en-US/xmlandnetfx/thread/149dd49d-27c3-4a92-9715-95c2cd624222

http://vstoolsforum.com/blogs/vbnet/archive/2008/ 08/26/linq-to-xml-with-asp-gridview-in-vb.aspx

看起来您的 xml 来自持久保存到 XML 的数据集。如果是这种情况,您还可以使用以下链接中的信息重新加载数据集:

http://msdn.microsoft.com/en-us/library/fx29c3yd.aspx

从那里您可以使用数据视图过滤数据集结果。

您还可以链接数据集:

http://www.hookedonlinq.com/LINQtoDatasets.ashx

You should be able to do this. Here's a few samples:

http://social.msdn.microsoft.com/Forums/en-US/xmlandnetfx/thread/149dd49d-27c3-4a92-9715-95c2cd624222

http://vstoolsforum.com/blogs/vbnet/archive/2008/08/26/linq-to-xml-with-asp-gridview-in-vb.aspx

It looks like your xml is from a dataset that was persisted to XML. If this is the case you could also reload the dataset using the info from this link:

http://msdn.microsoft.com/en-us/library/fx29c3yd.aspx

From there you can filter the dataset results with a dataview.

You can also linq over the dataset:

http://www.hookedonlinq.com/LINQtoDatasets.ashx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文