开发者

how to display geographical details in combo box?

i'm using 4 combo boxes for displaying latitude details.the latitude details are degree,minutes,seconds and north/south.when i select the city in combo box the latitude details from sql server 开发者_运维知识库(for that city) should be displayed.can anyone please help me how to fix this problem?


Try something along the lines of

<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>

and in your code-behind

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);
    }

(Be aware that the way I use the DataRow won't win you any points for elegance or use of best practices)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜