如何在组合框中显示地理细节?

时间:2010-02-19 12:21:59

标签: asp.net

我使用4个组合框来显示纬度细节。纬度细节是度,分,秒和北/南。当我在组合框中选择城市时,来自sql server 的纬度细节(对于那个城市) )应该显示。任何人都可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

尝试一下

的内容
<div>
    <asp:DropDownList ID="CityDropDown" runat="server">
        <asp:ListItem Text="London" Value="1"></asp:ListItem>
        <asp:ListItem Text="New York" Value="2"></asp:ListItem>
        <asp:ListItem Text="Copenhagen" Value="3"></asp:ListItem>
        <asp:ListItem Text="Moscow" Value="4"></asp:ListItem>
    </asp:DropDownList>

    Latitude: <asp:Label ID="LatitudeLabel" runat="server"></asp:Label>
    Longitude: <asp:Label ID="LongitudeLabel" runat="server"></asp:Label>

</div>

并在您的代码隐藏

protected override void OnInit(EventArgs e)
{
    this.CityDropDown.SelectedIndexChanged += new EventHandler(CityDropDown_SelectedIndexChanged);
    base.OnInit(e);
}

    void CityDropDown_SelectedIndexChanged(object sender, EventArgs e)
    {
        int cityId = Int32.Parse(CityDropDown.SelectedValue);

        /* Go get the latitude and longitude for the city from the database */

        DataRow dr = /* some datarow you have fetched from the database */

        int latSeconds = (int)dr["LatSeconds"];
        int latMinutes = (int)dr["LatMinutes"];
        int latDegrees = (int)dr["LatDegrees"];

        int longSeconds = (int)dr["LongSeconds"];
        int longMinutes = (int)dr["LongMinutes"];
        int longDegrees = (int)dr["LongDegress"];

        LatitudeLabel.Text = string.Format("{0}° {1}' {2}\"", latDegrees, latMinutes, latSeconds);
        LongitudeLabel.Text = string.Format("{0}° {1}' {2}\"", longDegrees, longMinutes, longSeconds);
    }

(请注意,我使用DataRow的方式不会为优雅或使用最佳实践赢得任何积分)

相关问题