论坛首页 Web前端技术论坛

C#用天气预报的WebServices

浏览 2883 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2010-12-23  

后台代码:

 

 

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            WeatherWS ws = new WeatherWS();
            IList<string> provinceDataSource = new List<string>();

            DataSet proDs = ws.getRegionDataset();
            ddlProvince.DataSource = proDs.Tables[0].DefaultView;
            ddlProvince.DataTextField = "RegionName";
            ddlProvince.DataValueField = "RegionID";
            ddlProvince.DataBind();
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {

        WeatherWS ws = new WeatherWS();
        string [] wsInfo = ws.getWeather(ddlCity.SelectedValue,"");
        string result = string.Empty;
        for (int i = 0; i < wsInfo.Length; i++)
        {
            result += wsInfo[i]+"<BR/>";
        }
        Label1.Text = result;

    }

    protected void ddlProvince_SelectedIndexChanged(object sender, EventArgs e)
    {
        WeatherWS ws = new WeatherWS();
        DataSet cityDs = ws.getSupportCityDataset(ddlProvince.SelectedValue);
        ddlCity.DataSource = cityDs.Tables[0].DefaultView;
        ddlCity.DataTextField = "CityName";
        ddlCity.DataValueField = "CityID";
        ddlCity.DataBind();
    }

 

 

.aspx代码

 

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:DropDownList ID="ddlProvince" runat="server" AutoPostBack="True" 
                        onselectedindexchanged="ddlProvince_SelectedIndexChanged">
                    </asp:DropDownList>
                    <asp:DropDownList ID="ddlCity" runat="server">
                    </asp:DropDownList>
                    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
                    <br />
                    <br />
                    <br />
                    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                </ContentTemplate>
            </asp:UpdatePanel>

 

 

 

访问速度很慢,,,...

 

 

第一步要添加Web引用



 

 

 

然后页面就有东西了.....webServices给的很明确了

  • 大小: 16 KB
论坛首页 Web前端技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics