Click here to Skip to main content
15,879,239 members
Please Sign up or sign in to vote.
1.00/5 (5 votes)
See more:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class xmlC : System.Web.UI.Page
{
   protected void Page_Load(object sender, EventArgs e)
   {
      if (!this.IsPostBack) {
         //Create a new global weather object
         GlobalWeather.GlobalWeather proxy = new GlobalWeather.GlobalWeather();
         //Create a new xml document object. We need xml implementation since the data is in xml format.
         XmlDocument xmlDoc = new XmlDocument();
         //Load all country/city names in to the xml document.
         xmlDoc.LoadXml(proxy.GetCitiesByCountry(""));
         //Query only country names and put them in to xml node list
         XmlNodeList xmlNodes = xmlDoc.GetElementsByTagName("Country");
         List<string> countryList = new List<string>();
         foreach (XmlNode node in xmlNodes) {
            if (!countryList.Contains(node.InnerText)) {
               //Loop through the country names and put them in to a list object
               countryList.Add(node.InnerText);
            }
         }
         countryList.Sort();
         //Bind the CountryDropDownList control.
         this.CountryDropDownList.DataSource = countryList;
         this.CountryDropDownList.DataBind();
         this.CountryDropDownList_SelectedIndexChanged(this.CountryDropDownList, new EventArgs());
      }
   }

   protected void CountryDropDownList_SelectedIndexChanged(object sender, System.EventArgs e)
   {
      if (this.CountryDropDownList.SelectedItem != null) {
         List<string> cityList = new List<string>();
         GlobalWeather.GlobalWeather proxy = new GlobalWeather.GlobalWeather();
         XmlDocument xmlDoc = new XmlDocument();
         //Load the xml document with all city names for the selected country.
         xmlDoc.LoadXml(proxy.GetCitiesByCountry(this.CountryDropDownList.SelectedValue));
         //Get all city names and put them in to xml node list.
         XmlNodeList xmlNodes = xmlDoc.GetElementsByTagName("City");
         foreach (XmlNode node in xmlNodes) {
            if (!cityList.Contains(node.InnerText)) {
               //Loop through the city names and put them in to a list object
               cityList.Add(node.InnerText);
            }
         }
         cityList.Sort();
         //Bind the CityDropDownList control.
         this.CityDropDownList.DataSource = cityList;
         this.CityDropDownList.DataBind();
      }
      else {
         this.CityDropDownList.DataSource = null;
         this.CityDropDownList.DataBind();
      }
   }

   protected void Page_LoadComplete(object sender, System.EventArgs e)
   {
      if (this.CountryDropDownList.SelectedItem != null && this.CityDropDownList.SelectedItem != null) {
         StringBuilder sb = new StringBuilder();
         GlobalWeather.GlobalWeather proxy = new GlobalWeather.GlobalWeather();
         //Get weather information for the selected country and city by using the "GetWeather" service method.
         string xmlStr = proxy.GetWeather(this.CityDropDownList.SelectedValue, this.CountryDropDownList.SelectedValue);
         bool success = false;
         try {
            XmlDocument xmlDoc = new XmlDocument();
            //Load the xml string data into xml document
            xmlDoc.LoadXml(xmlStr);
            XmlNode xmlNode = xmlDoc.DocumentElement();
            foreach (XmlNode node in xmlNode.ChildNodes) {
               if (node.Name == "Status") {
                  success = node.InnerText == "Success";
               }
               else {
                  //Loop through the nodes and put the information in the StringBuilder object.
                  sb.Append("" + node.Name + ": " + node.InnerText + "<br />");
               }
            }
         }
         catch (Exception ex) {
            sb.Append("Data Not Found");
         }
         if (success) {
            //If everything went well than show the information.
            this.weatherLabel.Text = sb.ToString;
         }
         else {
            this.weatherLabel.Text = "Data Not Found";
         }
      }
   }
   public _Default()
   {
      LoadComplete += Page_LoadComplete;
      Load += Page_Load;
      retu;
   }
}
Posted
Updated 18-Sep-14 8:43am
v3
Comments
Pheonyx 18-Sep-14 7:18am    
This is not a question.. this is a statement and a massive unformatted code dump.
Use the "Improve question" to format your code and explain your issue. My guess is you are calling a void function but expecting something to be returned?! But that is a guess.
Afzaal Ahmad Zeeshan 18-Sep-14 7:33am    
On which line of code?
[no name] 18-Sep-14 7:33am    
Please post your query in brief. This seems too complicated dear.
Thanks
Hemant Singh Rautela 18-Sep-14 7:39am    
Just Debug the code.... and then show us that error...

And just want to ask you what is this {A function without its return type or void} : public _Default()
[no name] 18-Sep-14 7:41am    
public void _Default()
The next error you are going to get is something about "retu" not being defined.

The problem is you have declared a method (public _Default()) without a return type

In the below code what is retu; ?
public _Default()
{
LoadComplete += Page_LoadComplete;
Load += Page_Load;
retu;
}

If you don't want to return anything then change it to

C#
public void _Default()
     {
         LoadComplete += Page_LoadComplete;
         Load += Page_Load;

     }
 
Share this answer
 
Yes, methods must have the return type. The C# programming language requires that. Methods that return no value must be declared void.
 
Share this answer
 
what does this mean?
C#
public _Default()
{
LoadComplete += Page_LoadComplete;
Load += Page_Load;
retu;
}


change this block of code as this is causing error.
 
Share this answer
 
XML
The methods must have the return type. The C# programming language requires that. Methods that return no value must be declared void.

i think you need to write like this

Public void _Default()
  {
     LoadComplete += Page_LoadComplete;
     Load += Page_Load;
  }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900