In that i'm getting available list of hotels with rates as xml string i'm trying to show it in gridview with help of xmldatasource
but not working.
Nitin_Gavhane
don't want it by using xslt. want using linq method.
Nitin
ds.ReadXml(new XmlTextReader(resultData));
GridView1.DataSource = ds;
GridView1.DataBind();
Hello:)
Look at your solutions of the three I've referred above——First you want an XmlDataSource,Second you are using manually data bind with DataTable or DataSet,The third question you want to a LINQ?
I don't know which way do you really want?You've mixed the three ways together!
For LINQ,Please make sure that your xml contents is well-fromatted correctly,and you can use Descedants method to read out duplicated issues and use XElement.Value to read out specific node's value。
Nitin_Gavhan...
Member
9 Points
20 Posts
XML string to Gridview binding
Dec 09, 2011 04:48 AM|LINK
Hi All,
I'm using third-party hotel API which is REST based web service.
In that i'm getting available list of hotels with rates as xml string i'm trying to show it in gridview with help of xmldatasource
but not working.
Is it correct way to show xml in grid or will i use dataset because i need to do many operation after binding i.e searching,sorting,paging?
find below inserted code. also tried ds.ReadXml(new System.IO.StringReader(doc.OuterXml),XmlReadMode.InferSchema); but getting error
Column name 'id' is defined for different mapping types.
Any help will be appreciated.
------------------------------------.cs------------------------------------------------ HotelApiBLL.HotelListRates hotelList = new HotelApiBLL.HotelListRates(); string resultData = hotelList.getHotelAvailabiality("vyn56uju89mimiiimiu9dkjajeeihurherheurhjfdbdporhvnrievhtyinuyutytb", "bangalore", "", "", 1, DateTime.Now.AddDays(2), DateTime.Now.AddDays(3), 2, 0, 0, 1, 1, "INR", 1, 1, 1, 1, 1, 1, 0, 0); System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); doc.LoadXml(resultData); xdsHotel.XPath = "iconnect/search_res/hotels"; xdsHotel.Data = doc.InnerXml; xdsHotel.DataBind(); GridView1.DataBind(); ---------------------------------.aspx------------------------------------------------ <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" DataSourceID="xdsHotel"> <Columns> <asp:TemplateField> <ItemTemplate> <div> <asp:Label runat="server" id="hname" text='<%# XPath("name")%>' ></asp:Label> </div> <table> <tr> <td> <%# XPath("address/city")%> </td> <td> <div><img src='<%# XPath("images/image/url")%>' ></div> </td> <td> </td> </tr> </table> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> <asp:XmlDataSource runat="server" ID="xdsHotel" EnableCaching="false"></asp:XmlDataSource> --------------------------------xml file----------------------------------------------- <?xml version="1.0" encoding="UTF-8" standalone="no"?> <iconnect xmlns="http://www.iconnect.in/connect/getAvailableHotelsWithRates"> <login> <iconnect_session>gdfgdfgdarwetlWEJEIdfsflkwouut236rviruvnuRIRJ</iconnect_session> <status>Connection Success</status> <status_flag>1</status_flag> <access_time>2011-12-06 03:25:44</access_time> </login> <search_n_avail_req> <search_q> <by_place>bangalore</by_place> <by_hotel_name/> <by_hotel_ids/> </search_q> <room_count>1</room_count> <avail_from>2011-12-08</avail_from> <avail_to>2011-12-09</avail_to> <adults>2</adults> <childs>0</childs> <childs_age>0</childs_age> <get_rooms>1</get_rooms> <get_price>1</get_price> <currency>INR</currency> <options> <activities>1</activities> <amenities>1</amenities> <route_map>1</route_map> <images>1</images> <room_types> <details>1</details> <image>1</image> </room_types> <packages> <details>0</details> <image>0</image> </packages> </options> </search_n_avail_req> <search_res> <res_status> <flag>1</flag> <errormsg/> </res_status> <hotels> <hotel> <id>1002</id> <name>Test Sunflower Hotel</name> <star_category>0</star_category> <description>t7u</description> <hotel_type>null</hotel_type> <hotel_grade>-1</hotel_grade> <address> <line_1>2/1 al-latheef building,</line_1> <line_2>ground floor, union street, bangalore</line_2> <line_3/> <city>Bangalore</city> <state>null</state> <country>null</country> <zipcode>560001</zipcode> </address> <hotel_contacts> <phone1>9900087673</phone1> <phone2>9900087673</phone2> </hotel_contacts> <default_check_in/> <default_check_out/> <activities/> <amenities> <amenity id="101"> <name>24 hour Coffee Shop</name> <extra_cost>1</extra_cost> </amenity> <amenity id="62"> <name>Air Conditioned Public Area</name> <extra_cost>1</extra_cost> </amenity> <amenity id="110"> <name>Audio Visual Equipment</name> <extra_cost>0</extra_cost> </amenity> </amenities> <route_map> <latitude>121</latitude> <longitude>99</longitude> </route_map> <images> <image id="1"> <url>http://magicrooms.in/hotels/hotelimg/1002_1321960321.jpeg</url> <tn>http://magicrooms.in/hotels/hotelimg/tn_1002_1321960321.jpeg</tn> <title>Logo</title> </image> </images> <room_types> <room id="1"> <id>1</id> <name>Standard</name> <img_url>http://iconnect.in/hotel_images/room_types/1002_1_1319027761.jpeg</img_url> <img_thumbnail>http://iconnect.in/hotel_images/room_types/tn_1002_1_1319027761.jpeg</img_thumbnail> <total_count>20</total_count> <single_flag>0</single_flag> <double_flag>1</double_flag> <triple_flag>1</triple_flag> <max_pax>5</max_pax> <description/> <inclusions/> <cancel_policy/> <Promotions/> </room> <room id="2"> <id>2</id> <name>Deluxe</name> <img_url>http://iconnect.in/hotel_images/room_types/null</img_url> <img_thumbnail>http://iconnect.in/hotel_images/room_types/tn_null</img_thumbnail> <total_count>20</total_count> <single_flag>0</single_flag> <double_flag>1</double_flag> <triple_flag>0</triple_flag> <max_pax>3</max_pax> <description><![CDATA[Deluxe Room.]]></description> <inclusions/> <cancel_policy/> <Promotions/> </room> </room_types> <Rates> <room_types> <room_type id="1"> <id>1</id> <name>Standard</name> <meal_plans> <meal_plan id="1"> <name>Continental plan</name> <short_name>CP</short_name> <mp_id>1</mp_id> <display_rate>2000.0</display_rate> <base_rate>1881.0</base_rate> <child_rate>0.0</child_rate> <extra_adult>0.0</extra_adult> <disc>99.0</disc> <tax>344.53</tax> <promotions/> <total>2225.5299999999997</total> <auxiliary_breakups> <date value="2011-12-08"> <room id="1"> <auxilary id="2"> <aux_id>2</aux_id> <aux_name>Discount</aux_name> <aux_type>S</aux_type> <aux_value>5.0</aux_value> <aux_amount>99.0</aux_amount> </auxilary> <auxilary id="1"> <aux_id>1</aux_id> <aux_name>Sales tax</aux_name> <aux_type>A</aux_type> <aux_value>10.0</aux_value> <aux_amount>188.1</aux_amount> </auxilary> <auxilary id="1"> <aux_id>1</aux_id> <aux_name>Sales tax</aux_name> <aux_type>A</aux_type> <aux_value>3.0</aux_value> <aux_amount>56.43</aux_amount> </auxilary> <auxilary id="3"> <aux_id>3</aux_id> <aux_name>Luxury tax</aux_name> <aux_type>A</aux_type> <aux_value>100.0</aux_value> <aux_amount>100.0</aux_amount> </auxilary> </room> </date> </auxiliary_breakups> </meal_plan> </meal_plans> </room_type> <room_type id="2"> <id>2</id> <name>Deluxe</name> <meal_plans> <meal_plan id="1"> <name>Continental plan</name> <short_name>CP</short_name> <mp_id>1</mp_id> <display_rate>3000.0</display_rate> <base_rate>2821.5</base_rate> <child_rate>0.0</child_rate> <extra_adult>0.0</extra_adult> <disc>148.5</disc> <tax>466.79499999999996</tax> <promotions/> <total>3288.295</total> <auxiliary_breakups> <date value="2011-12-08"> <room id="1"> <auxilary id="2"> <aux_id>2</aux_id> <aux_name>Discount</aux_name> <aux_type>S</aux_type> <aux_value>5.0</aux_value> <aux_amount>148.5</aux_amount> </auxilary> <auxilary id="1"> <aux_id>1</aux_id> <aux_name>Sales tax</aux_name> <aux_type>A</aux_type> <aux_value>10.0</aux_value> <aux_amount>282.15</aux_amount> </auxilary> <auxilary id="1"> <aux_id>1</aux_id> <aux_name>Sales tax</aux_name> <aux_type>A</aux_type> <aux_value>3.0</aux_value> <aux_amount>84.645</aux_amount> </auxilary> <auxilary id="3"> <aux_id>3</aux_id> <aux_name>Luxury tax</aux_name> <aux_type>A</aux_type> <aux_value>100.0</aux_value> <aux_amount>100.0</aux_amount> </auxilary> </room> </date> </auxiliary_breakups> </meal_plan> </meal_plans> </room_type> </room_types> </Rates> </hotel> </hotels> </search_res> </iconnect>amit.jain
Star
11225 Points
1815 Posts
Re: XML string to Gridview binding
Dec 09, 2011 06:29 AM|LINK
try defining XSLT schema for your xml file as source for Gridview
Refer GridView XMLDataSource example for more info
amiT jaiN
ASP.NET C# VB Articles And Code Examples
Nitin_Gavhan...
Member
9 Points
20 Posts
Re: XML string to Gridview binding
Dec 09, 2011 06:39 AM|LINK
Need to attach xml in code behind not using smart tag i.e using design view.
kuber.manral
Contributor
3051 Points
714 Posts
Re: XML string to Gridview binding
Dec 09, 2011 06:58 AM|LINK
Hi,
I havn't find this ds.ReadXml, using in your Code. Please eloborate ?
Visit My Blog
Nitin_Gavhan...
Member
9 Points
20 Posts
Re: XML string to Gridview binding
Dec 09, 2011 07:08 AM|LINK
Hi kuber,
I also tried below code
ds.ReadXml(new XmlTextReader(resultData));
GridView1.DataSource = ds;
GridView1.DataBind();
but getting error as below
Column name 'id' is defined for different mapping types
amit.jain
Star
11225 Points
1815 Posts
Re: XML string to Gridview binding
Dec 09, 2011 07:14 AM|LINK
amiT jaiN
ASP.NET C# VB Articles And Code Examples
Nitin_Gavhan...
Member
9 Points
20 Posts
Re: XML string to Gridview binding
Dec 10, 2011 05:37 AM|LINK
I don't want it by using xslt. want using linq method.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: XML string to Gridview binding
Dec 11, 2011 12:26 AM|LINK
Hello:)
Look at your solutions of the three I've referred above——First you want an XmlDataSource,Second you are using manually data bind with DataTable or DataSet,The third question you want to a LINQ?
I don't know which way do you really want?You've mixed the three ways together!
For LINQ,Please make sure that your xml contents is well-fromatted correctly,and you can use Descedants method to read out duplicated issues and use XElement.Value to read out specific node's value。
Sample looks like this——
<group>
<customer>
<email>testing@testing.com></email>
</customer>
<customer>
<email>testing2@testing.com</email>
</customer>
</group>
var query = from result in xml.Descedants("customer")
select new
{
email = result.Element("email").Value
};
gridview1.DataSource = query;
gridview1.DataBind();