大学IT网 - 最懂大学生的IT学习网站! QQ资料交流群:367606806
当前位置:大学IT网 > C#技巧 > C#用天气预报的WebServices

C#用天气预报的WebServices

关键词:天气预报WebServicesC#  阅读(904) 赞(15)

[摘要]本文是对C#用天气预报的WebServices的讲解,对学习C#编程技术有所帮助,与大家分享。

后台代码:

protectedvoidPage_Load(objectsender,EventArgse)
    {
    if(!IsPostBack)
    {
    WeatherWSws=newWeatherWS();
    IList<string>provinceDataSource=newList<string>();
    DataSetproDs=ws.getRegionDataset();
    ddlProvince.DataSource=proDs.Tables[0].DefaultView;
    ddlProvince.DataTextField="RegionName";
    ddlProvince.DataValueField="RegionID";
    ddlProvince.DataBind();
    }
    }
    protectedvoidButton1_Click(objectsender,EventArgse)
    {
    WeatherWSws=newWeatherWS();
    string[]wsInfo=ws.getWeather(ddlCity.SelectedValue,"");
    stringresult=string.Empty;
    for(inti=0;i<wsInfo.Length;i++)
    {
    result+=wsInfo[i]+"<BR/>";
    }
    Label1.Text=result;
    }
    protectedvoidddlProvince_SelectedIndexChanged(objectsender,EventArgse)
    {
    WeatherWSws=newWeatherWS();
    DataSetcityDs=ws.getSupportCityDataset(ddlProvince.SelectedValue);
    ddlCity.DataSource=cityDs.Tables[0].DefaultView;
    ddlCity.DataTextField="CityName";
    ddlCity.DataValueField="CityID";
    ddlCity.DataBind();
    }

.aspx代码


<asp:UpdatePanelID="UpdatePanel1"runat="server">
 <ContentTemplate> 
<asp:DropDownListID="ddlProvince"runat="server"AutoPostBack="True" onselectedindexchanged="ddlProvince_SelectedIndexChanged"> </asp:DropDownList>
 <asp:DropDownListID="ddlCity"runat="server"> </asp:DropDownList> 
<asp:ButtonID="Button1"runat="server"onclick="Button1_Click"Text="Button"/> 
<asp:LabelID="Label1"runat="server"Text="Label"></asp:Label> 
</ContentTemplate> 
</asp:UpdatePanel>
访问速度很慢,,,...


第一步要添加Web引用




相关评论