住所検索エクステンダを使用すると、郵便番号のほか、市外局番や全国地方公共団体コードから住所情報を検索できます。※住所検索エクステンダの機能を有効にするには、「JPAddress for ASP.NET」が必要です。
using System; using System.Drawing; using GrapeCity.Web.Input.IMExtenders; public partial class Input_GcAddress : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { // 検索動作を設定します。 AddressOutputSetting AddressOutputSetting1 = GcAddress1.GetAddressOutputSetting(GcTextBox1); AddressOutputSetting1.AddressQueryMode = (AddressQueryMode)int.Parse(DropDownList1.SelectedValue); AddressOutputSetting1.SplitAreaDetails = CheckBox1.Checked; GcAddress1.SetAddressOutputSetting(GcTextBox1, AddressOutputSetting1); switch( int.Parse(DropDownList1.SelectedValue)) { case 1: case 2: case 3: Label1.Text = "郵便番号:"; TextBox2.Enabled = true; TextBox2.BackColor = SystemColors.Window; TextBox3.Enabled = true; TextBox3.BackColor = SystemColors.Window; TextBox4.Enabled = true; TextBox4.BackColor = SystemColors.Window; TextBox5.Enabled = false; TextBox5.BackColor = Color.LightGray; break; case 4: Label1.Text = "市外局番:"; TextBox2.Enabled = false; TextBox2.BackColor = Color.LightGray; TextBox3.Enabled = false; TextBox3.BackColor = Color.LightGray; TextBox4.Enabled = false; TextBox4.BackColor = Color.LightGray; TextBox5.Enabled = true; TextBox5.BackColor = SystemColors.Window; break; case 5: TextBox2.Enabled = true; TextBox2.BackColor = SystemColors.Window; TextBox3.Enabled = false; TextBox3.BackColor = Color.LightGray; TextBox4.Enabled = true; TextBox4.BackColor = SystemColors.Window; TextBox5.Enabled = false; TextBox5.BackColor = Color.LightGray; Label1.Text = "全国地方公共団体コード:"; break; default: break; } } }
Imports GrapeCity.Web.Input.IMExtenders Imports System.Drawing Partial Class Input_GcAddress Inherits System.Web.UI.Page Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click ' 検索動作を設定します。 Dim AddressOutputSetting1 As AddressOutputSetting = GcAddress1.GetAddressOutputSetting(GcTextBox1) AddressOutputSetting1.AddressQueryMode = DropDownList1.SelectedValue AddressOutputSetting1.SplitAreaDetails = CheckBox1.Checked GcAddress1.SetAddressOutputSetting(GcTextBox1, AddressOutputSetting1) Select Case DropDownList1.SelectedValue Case 1, 2, 3 Label1.Text = "郵便番号:" TextBox2.Enabled = True TextBox2.BackColor = SystemColors.Window TextBox3.Enabled = True TextBox3.BackColor = SystemColors.Window TextBox4.Enabled = True TextBox4.BackColor = SystemColors.Window TextBox5.Enabled = False TextBox5.BackColor = Color.LightGray Case 4 Label1.Text = "市外局番:" TextBox2.Enabled = False TextBox2.BackColor = Color.LightGray TextBox3.Enabled = False TextBox3.BackColor = Color.LightGray TextBox4.Enabled = False TextBox4.BackColor = Color.LightGray TextBox5.Enabled = True TextBox5.BackColor = SystemColors.Window Case 5 TextBox2.Enabled = True TextBox2.BackColor = SystemColors.Window TextBox3.Enabled = False TextBox3.BackColor = Color.LightGray TextBox4.Enabled = True TextBox4.BackColor = SystemColors.Window TextBox5.Enabled = False TextBox5.BackColor = Color.LightGray Label1.Text = "全国地方公共団体コード:" End Select End Sub End Class
<%@ page title="" language="C#" masterpagefile="~/MasterPage.master" autoeventwireup="true" inherits="Input_GcAddress, App_Web_nb5d2exk" stylesheettheme="SkinFile" %> <%@ Register assembly="GrapeCity.Web.Input.v100, Version=10.0.4006.2012, Culture=neutral, PublicKeyToken=c3bd7c1dccef5128" namespace="GrapeCity.Web.Input.IMExtenders" tagprefix="im_extenders" %> <%@ Register assembly="GrapeCity.Web.Input.v100, Version=10.0.4006.2012, Culture=neutral, PublicKeyToken=c3bd7c1dccef5128" namespace="GrapeCity.Web.Input.IMMask" tagprefix="im_mask" %> <%@ Register assembly="GrapeCity.Web.Input.v100, Version=10.0.4006.2012, Culture=neutral, PublicKeyToken=c3bd7c1dccef5128" namespace="GrapeCity.Web.Input.IMEdit" tagprefix="im_edit" %> <%@ Register assembly="GrapeCity.Web.Input.v100, Version=10.0.4006.2012, Culture=neutral, PublicKeyToken=c3bd7c1dccef5128" namespace="GrapeCity.Web.Input.IMList" tagprefix="im_list" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> <script type="text/javascript" id="GcAddress1_Script0"> function GcAddress1_AddressOutputting(sender, eArgs) { var lines = new Array(); switch (document.getElementById("<%=DropDownList1.ClientID %>").selectedIndex) { case 0: case 1: case 2: // 郵便番号からの検索結果を取得します。 var addresses = eArgs.AddressInfos; for (var i = 0; i < addresses.length; i++) { lines[i] = addresses[i].GetPrefecture() + addresses[i].GetCity() + addresses[i].GetTown() + addresses[i].GetArea(); // 大口事業所の結果が含まれている場合は事業所名を追加します。 if (addresses[i].GetIsCompanyAddressInfo()) { lines[i] += addresses[i].GetCompanyName(); } } break; case 3: // 市外局番からの検索結果を取得します。 var phonecodes = eArgs.PhoneCodeInfos; for (var i = 0; i < phonecodes.length; i++) { lines[i] = phonecodes[i].GetPrefecture() + phonecodes[i].GetCity() + phonecodes[i].GetRemark(); } break; case 4: // 全国地方公共団体コードからの検索結果を取得します。 var regions = eArgs.RegionInfos; for (var i = 0; i < regions.length; i++) { lines[i] = regions[i].GetName(); } break; default: break; } FindIMControl("<%=GcTextBox2.ClientID %>").SetLines(lines); } </script> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <div class="sample"> <table> <tr> <td class="controlsTd"> <asp:Label ID="Label1" runat="server" Text="郵便番号:"></asp:Label> </td> <td align="left"> <im_edit:GcTextBox ID="GcTextBox1" runat="server" Format="9" HasLoadFromXml="True" ImeMode="InActive"></im_edit:GcTextBox> </td> </tr> <tr> <td class="controlsTd">住所:</td> <td align="left"> <asp:TextBox ID="TextBox1" runat="server" Width="300px"></asp:TextBox> </td> </tr> <tr> <td class="controlsTd">住所(カナ):</td> <td align="left"> <asp:TextBox ID="TextBox2" runat="server" Width="300px"></asp:TextBox> </td> </tr> <tr> <td class="controlsTd">郵便番号:</td> <td align="left"> <asp:TextBox ID="TextBox3" runat="server" Width="300px"></asp:TextBox> </td> </tr> <tr> <td class="controlsTd">全国地方公共団体コード:</td> <td align="left"> <asp:TextBox ID="TextBox4" runat="server" Width="300px"></asp:TextBox> </td> </tr> <tr> <td class="controlsTd">市外局番: </td> <td align="left"> <asp:TextBox ID="TextBox5" runat="server" Width="300px" BackColor="Silver"></asp:TextBox> </td> </tr> <tr> <td class="controlsTd">すべての住所リスト:</td> <td> <im_edit:GcTextBox ID="GcTextBox2" runat='server' HasLoadFromXml="True" Height="80px" MultiLine="True" ScrollBarMode="Automatic" ScrollBars="Both" Width="400px" WordWrap="False"></im_edit:GcTextBox> </td> </tr> </table> </div> <im_extenders:GcAddress ID="GcAddress1" runat="server" ClientEvents-AddressOutputting="GcAddress1_AddressOutputting"> <AddressSettingitem controlid = "GcTextBox1" AddressOutput = "TextBox1" AddressKanaOutput = "TextBox2" JISCodeOutput="TextBox4" PhoneCodeOutput="TextBox5" ZipCodeOutput="TextBox3" generatecompanyaddresskana="true"/> </im_extenders:GcAddress> <table class="inputTable"> <tr> <th class="inputTh">検索の対象</th> <td class="inputTd"> <asp:DropDownList ID="DropDownList1" runat="server"> <asp:ListItem Selected="True" Value="1">郵便番号から一般の住所情報を検索</asp:ListItem> <asp:ListItem Value="2">郵便番号から大口事業所の住所情報を検索</asp:ListItem> <asp:ListItem Value="3">郵便番号から一般と大口事業所の住所情報を検索</asp:ListItem> <asp:ListItem Value="4">市外局番から住所情報を検索</asp:ListItem> <asp:ListItem Value="5">全国地方公共団体コードから地域情報を検索</asp:ListItem> </asp:DropDownList> </td> </tr> <tr> <th class="inputTh">丁目の分割</th> <td class="inputTd"> <asp:CheckBox ID="CheckBox1" runat="server" Checked="True" Text="複数の丁目が含まれているときに分割する" /> </td> </tr> </table> <center> <asp:Button ID="Button1" runat="server" CssClass="setButton" Text="設定" onclick="Button1_Click" /> </center> </asp:Content>