using System;
using System.Text;
using System.IO;
using System.Collections;
using System.Xml;
using System.Net;
using System.Web;
using System.Web.UI;
namespace Caffeinated.TestPages
{
// Helper class to store the response
public class ZillowRateSummary
{
public int Is30YearFixedDown
{
get { return Math.Sign(Today30YearFixed -LastWeek30YearFixed); }
}
public int Is15YearFixedDown
{
get { return Math.Sign(Today15YearFixed -LastWeek15YearFixed); }
}
public int Is51ARMDown
{
get { return Math.Sign(Today51ARM -LastWeek51ARM); }
}
public decimal Today30YearFixed;
public decimal Today15YearFixed;
public decimal Today51ARM;
public decimal LastWeek30YearFixed;
public decimal LastWeek15YearFixed;
public decimal LastWeek51ARM;
}
public partial class ZillowDemoPage : System.Web.UI.Page
{
// Get your Zillow Web Services ID (ZWSID) at http://www.zillow.com/webservice/Registration.htm
const string zwsid = "X1-ZWz1bqxeoxgiyz_282ek";
const string state = "ma";
protected static string GetTrendClass(int Trend)
{
if (Trend > 0)
{
return "rising";
}
else if (Trend == 0)
{
return "steady";
}
else
{
return "falling";
}
}
protected static string GetTrendIcon(int Trend)
{
if (Trend > 0)
{
// Unicode character for up arrow
return "▲";
}
else if (Trend == 0)
{
return "No Change";
}
else
{
// Unicode character for down arrow
return "▼";
}
}
// The technical details of the GetRateSummary API are at http://www.zillow.com/howto/api/GetRateSummary.htm
protected static ZillowRateSummary GetRateSummary()
{
// Construct the url
String url = String.Format("http://www.zillow.com/webservice/GetRateSummary.htm?zws-id={0}&state={1}", zwsid, state);
ZillowRateSummary zrs = new ZillowRateSummary();
try
{
// Make the HTTP request / get the response
HttpWebRequest Request = (System.Net.HttpWebRequest)HttpWebRequest.Create(url);
HttpWebResponse Response = (HttpWebResponse)Request.GetResponse();
// Parse the HTTP response into an XML document
XmlDocument xml = new XmlDocument();
xml.Load(Response.GetResponseStream());
XmlElement root = xml.DocumentElement;
// Get today's rates via XPath
XmlNode xmlNode = root.SelectSingleNode("//response/today/rate[@loanType='thirtyYearFixed']");
zrs.Today30YearFixed = decimal.Parse(xmlNode.InnerText);
xmlNode = root.SelectSingleNode("//response/today/rate[@loanType='fifteenYearFixed']");
zrs.Today15YearFixed = decimal.Parse(xmlNode.InnerText);
xmlNode = root.SelectSingleNode("//response/today/rate[@loanType='fiveOneARM']");
zrs.Today51ARM = decimal.Parse(xmlNode.InnerText);
// Get last weeks's rates via XPath
xmlNode = root.SelectSingleNode("//response/lastWeek/rate[@loanType='thirtyYearFixed']");
zrs.LastWeek30YearFixed = decimal.Parse(xmlNode.InnerText);
xmlNode = root.SelectSingleNode("//response/lastWeek/rate[@loanType='fifteenYearFixed']");
zrs.LastWeek15YearFixed = decimal.Parse(xmlNode.InnerText);
xmlNode = root.SelectSingleNode("//response/lastWeek/rate[@loanType='fiveOneARM']");
zrs.LastWeek51ARM = decimal.Parse(xmlNode.InnerText);
Response.Close();
}
catch (Exception ex)
{
}
return zrs;
}
}
}
I simply want to add a drop downon the default.aspx page to select a state, which will change the value in on
const string state = "ma"; on the code behind page.
that's it I have been doing some searching , but not ever sure what to search for.. Thank you for any help
I found this DropDownList online, so you can just copy and paste this in your aspx page wherver you want. I have set it to AutoPostBack="true", which means that when you change the state, the page will post back and your server code will be executed.
444
0 Points
1 Post
Very Simple, but I'm lost
May 17, 2012 02:40 PM|LINK
Hi,
I am very new to asp.net and have been pulling my hair out to find a solution to something very simple. I have been using this zillow api widget:
aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Zillow.aspx.cs" Inherits="Caffeinated.TestPages.ZillowDemoPage" %> <%@ Import Namespace="Caffeinated.TestPages" %> <% ZillowRateSummary MortgageRates = GetRateSummary(); %> <html> <body> <style> * { font-family:Myriad,Arial,Helvetica,sans-serif; font-size: 9pt } a { color: blue; text-decoration: none } a:hover { text-decoration: underline } .falling { color: green } .rising { color: red } .steady { color: orange } #morgagerates { width: 200 } </style> <div class="hslice" id="morgagerates"> <b class="entry-title">Mortgage Rates</b> <table> <tr> <td align="left"></td> <td align="center">Today's<br>Rates</td> <td align="center">Last<br>Week</td> </tr> <tr> <td align="left"><a href="http://www.zillow.com/30_Year_Fixed_Mortgage_Rates/">30 Year Fixed</a></td> <td class="<% =GetTrendClass(MortgageRates.Is30YearFixedDown)%>" align="center"><% =MortgageRates.Today30YearFixed %>%</td> <td class="<% =GetTrendClass(MortgageRates.Is30YearFixedDown)%>" align="center"> <% =GetTrendIcon(MortgageRates.Is30YearFixedDown)%><% =MortgageRates.LastWeek30YearFixed %>% </td> </tr> <tr> <td align="left"><a href="http://www.zillow.com/15_Year_Fixed_Mortgage_Rates/">15 Year Fixed</a></td> <td class="<% =GetTrendClass(MortgageRates.Is15YearFixedDown)%>" align="center"><% =MortgageRates.Today15YearFixed %>%</id> <td class="<% =GetTrendClass(MortgageRates.Is15YearFixedDown)%>" align="center"> <% =GetTrendIcon(MortgageRates.Is15YearFixedDown)%><% =MortgageRates.LastWeek15YearFixed %>% </td> </tr> <tr> <td align="left"><a href="http://www.zillow.com/5-1_ARM_Mortgage_Rates/">5.1 ARM</a></td> <td class="<% =GetTrendClass(MortgageRates.Is51ARMDown)%>" align="center"><% =MortgageRates.Today51ARM %>%</td> <td class="<% =GetTrendClass(MortgageRates.Is51ARMDown)%>" align="center"> <% =GetTrendIcon(MortgageRates.Is51ARMDown)%><% =MortgageRates.LastWeek51ARM %>% </td> </tr> </table> <a href="http://www.zillow.com/mortgage"> See more mortgage rates at Zillow.<br> <img border="0" alt="Zillow Mortgages" src="http://www.zillow.com/static/logos/zmm_logo_large.gif"> </a> </div> </body> </html>.cs:
using System; using System.Text; using System.IO; using System.Collections; using System.Xml; using System.Net; using System.Web; using System.Web.UI; namespace Caffeinated.TestPages { // Helper class to store the response public class ZillowRateSummary { public int Is30YearFixedDown { get { return Math.Sign(Today30YearFixed -LastWeek30YearFixed); } } public int Is15YearFixedDown { get { return Math.Sign(Today15YearFixed -LastWeek15YearFixed); } } public int Is51ARMDown { get { return Math.Sign(Today51ARM -LastWeek51ARM); } } public decimal Today30YearFixed; public decimal Today15YearFixed; public decimal Today51ARM; public decimal LastWeek30YearFixed; public decimal LastWeek15YearFixed; public decimal LastWeek51ARM; } public partial class ZillowDemoPage : System.Web.UI.Page { // Get your Zillow Web Services ID (ZWSID) at http://www.zillow.com/webservice/Registration.htm const string zwsid = "X1-ZWz1bqxeoxgiyz_282ek"; const string state = "ma"; protected static string GetTrendClass(int Trend) { if (Trend > 0) { return "rising"; } else if (Trend == 0) { return "steady"; } else { return "falling"; } } protected static string GetTrendIcon(int Trend) { if (Trend > 0) { // Unicode character for up arrow return "▲"; } else if (Trend == 0) { return "No Change"; } else { // Unicode character for down arrow return "▼"; } } // The technical details of the GetRateSummary API are at http://www.zillow.com/howto/api/GetRateSummary.htm protected static ZillowRateSummary GetRateSummary() { // Construct the url String url = String.Format("http://www.zillow.com/webservice/GetRateSummary.htm?zws-id={0}&state={1}", zwsid, state); ZillowRateSummary zrs = new ZillowRateSummary(); try { // Make the HTTP request / get the response HttpWebRequest Request = (System.Net.HttpWebRequest)HttpWebRequest.Create(url); HttpWebResponse Response = (HttpWebResponse)Request.GetResponse(); // Parse the HTTP response into an XML document XmlDocument xml = new XmlDocument(); xml.Load(Response.GetResponseStream()); XmlElement root = xml.DocumentElement; // Get today's rates via XPath XmlNode xmlNode = root.SelectSingleNode("//response/today/rate[@loanType='thirtyYearFixed']"); zrs.Today30YearFixed = decimal.Parse(xmlNode.InnerText); xmlNode = root.SelectSingleNode("//response/today/rate[@loanType='fifteenYearFixed']"); zrs.Today15YearFixed = decimal.Parse(xmlNode.InnerText); xmlNode = root.SelectSingleNode("//response/today/rate[@loanType='fiveOneARM']"); zrs.Today51ARM = decimal.Parse(xmlNode.InnerText); // Get last weeks's rates via XPath xmlNode = root.SelectSingleNode("//response/lastWeek/rate[@loanType='thirtyYearFixed']"); zrs.LastWeek30YearFixed = decimal.Parse(xmlNode.InnerText); xmlNode = root.SelectSingleNode("//response/lastWeek/rate[@loanType='fifteenYearFixed']"); zrs.LastWeek15YearFixed = decimal.Parse(xmlNode.InnerText); xmlNode = root.SelectSingleNode("//response/lastWeek/rate[@loanType='fiveOneARM']"); zrs.LastWeek51ARM = decimal.Parse(xmlNode.InnerText); Response.Close(); } catch (Exception ex) { } return zrs; } } }I simply want to add a drop downon the default.aspx page to select a state, which will change the value in on const string state = "ma"; on the code behind page.
that's it I have been doing some searching , but not ever sure what to search for.. Thank you for any help
bullpit
All-Star
21838 Points
4822 Posts
Re: Very Simple, but I'm lost
May 17, 2012 07:08 PM|LINK
I found this DropDownList online, so you can just copy and paste this in your aspx page wherver you want. I have set it to AutoPostBack="true", which means that when you change the state, the page will post back and your server code will be executed.
Then just use the value selected in your code like:
DropDownListState.SelectedValue
Max
Let Me Google That For You!