使用下拉列表生成5个州的天气超链接和来自RSS源的摘要

时间:2015-07-15 02:00:20

标签: c# asp.net hyperlink rss

我的目标是从下拉列表中选择一个州。选择州后,我的网页应显示标题和摘要 对于所选状态的每个警告。标题应该超链接到可以在项目的link元素中找到的URL。每个警告都应包含超链接和摘要。我目前不确定如何使用我目前的代码显示此数据。我现在正在使用案例,我认为这是完成此过程的最佳方式。

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
    <asp:DropDownList ID="stateDropDownList" runat="server" AutoPostBack="True" OnSelectedIndexChanged="stateDropDownList_SelectedIndexChanged">
        <asp:ListItem>Select a State</asp:ListItem>
        <asp:ListItem>Alabama</asp:ListItem>
        <asp:ListItem>Indiana</asp:ListItem>
        <asp:ListItem>California</asp:ListItem>
        <asp:ListItem>Illinois</asp:ListItem>
        <asp:ListItem>Minnesota</asp:ListItem>
    </asp:DropDownList><br /><hr /><br />
</div>

<div style="margin-left: 20px; margin-top: 20px; font-family: Arial">

//This is the area for output, not really sure what would be the best to use to display the data.

</div>

</form>
</body>
</html>

这是我的CS。

namespace WebForm1
{
public partial class WebForm1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void stateDropDownList_SelectedIndexChanged(object sender, EventArgs e)
    {
        String headlineTopic = stateDropDownList.SelectedValue;
        XmlDocument document = new XmlDocument();
        XmlNodeList items = document.GetElementsByTagName("item");

        switch (headlineTopic)
        {
            case "Alabama":
                document.Load("http://www.weather.gov/alerts/al.atom");
                foreach (XmlNode n in items)
                {
                    Response.Write("<p><a href='" + n["link"].InnerText + "'>" + n["title"].InnerText + n["Summary"].InnerText + "</a></p>");
                }
                break;

            case "Indiana":
                document.Load("http://www.weather.gov/alerts/in.atom");
                foreach (XmlNode n in items)
                {
                    Response.Write("<p><a href='" + n["link"].InnerText + "'>" + n["title"].InnerText + n["Summary"].InnerText + "</a></p>");
                }
                break;

            case "California":
                document.Load("http://www.weather.gov/alerts/ca.atom");
                foreach (XmlNode n in items)
                {
                    Response.Write("<p><a href='" + n["link"].InnerText + "'>" + n["title"].InnerText + n["Summary"].InnerText + "</a></p>");
                }
                break;

            case "Illinois":
                document.Load("http://www.weather.gov/alerts/il.atom");
                foreach (XmlNode n in items)
                {
                    Response.Write("<p><a href='" + n["link"].InnerText + "'>" + n["title"].InnerText + n["Summary"].InnerText + "</a></p>");
                }
                break;

            case "Minnesota":
                document.Load("http://www.weather.gov/alerts/mn.atom");
                foreach (XmlNode n in items)
                {
                    Response.Write("<p><a href='" + n["link"].InnerText + "'>" + n["title"].InnerText + n["Summary"].InnerText + "</a></p>");
                }
                break;
    }
  }   
 }
}

0 个答案:

没有答案