我正在查詢LINQ中的xml文檔,並希望在gridview中顯示結果以允許用戶從列表中進行選擇。在Gridview中顯示LINQ TO XML查詢的結果
查詢是作爲用戶輸入的結果。
這是我的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>
非常感謝klabranche,我現在可以查看網格視圖的結果,但不能似乎改變根元素是它直接生成從一個oracle數據庫。 有關如何將檢索到的數字轉換爲2位小數的任何建議? 在此先感謝 –
user161314
2009-08-22 17:11:55
你是什麼意思,你不能改變根元素?你想做什麼? – klabranche 2009-08-22 17:40:46
至於格式。由於您綁定到網格並讓網格生成列,因此您需要在代碼中進行格式設置。這裏是一個示例,說明如何做到這一點。代碼格式爲日期,但您可以按照自己的意願進行格式化。只要看看格式化字符串。 http://stackoverflow.com/questions/1176865/unable-to-format-date-in-dataset-column-gridview – klabranche 2009-08-22 17:42:27