.NET ------ 通过身份证号获取省市县
实现输入正确的身份证号后,点击图片校检将省市区(县)和年龄计算出来
前面页面展示
代码:
<tr> <td width="15%" align="right">身份证号:</td> <td align="left" bgcolor="#FFFFFF" width="35%"> <asp:TextBox MaxLength="18" ID="tbStuCardCode" runat="server"></asp:TextBox> <asp:ImageButton ID="btnCheckCard" runat="server" ImageUrl="~/qdAdmin/qdimages/check.png" title="校验检查" onclick="btncheckTel_Click" ImageAlign="AbsMiddle"/> <br><asp:Label ID="LabelCheckCardMsg" runat="server" ForeColor="#FF3300"></asp:Label> </td> <td width="15%" align="right">户籍地:</td> <td align="left" bgcolor="#FFFFFF" width="35%"> <asp:DropDownList ID="ddlPlaceSheng" runat="server" AutoPostBack="True" onselectedindexchanged="ddlSheng_SelectedIndexChanged" Width="90px"></asp:DropDownList> <asp:DropDownList ID="ddlPlaceCity" runat="server" AutoPostBack="True" onselectedindexchanged="ddlSheng_SelectedIndexChanged" Width="90px"></asp:DropDownList> <asp:DropDownList ID="ddlPlaceArea" runat="server" Width="90px"></asp:DropDownList> </td> </tr>
后面代码展示
代码
else if (btn.ID == "btnCheckCard") { this.LabelCheckCardMsg.Text = string.Empty; string s = this.tbStuCardCode.Text.Trim(); if (s.Length != 18) { this.LabelCheckCardMsg.Text = "请正确输入身份证号"; return; } string sCard = "086" + s.Substring(0, 6); List<ITEM.Model.qdCnt4.FourCollsType> mTypeList = _bllTypeColls.GetListSelFourCollsType3("TypeCollCode", base.EnterpriseGuid, " and TypeCollMark='" + sCard + "'"); if (mTypeList.Count == 1) { string sTypeCollCode = mTypeList[0].TypeCollCode; //通过身份证号获取 省、市、区(县) this.ddlPlaceSheng.SelectedValue = sTypeCollCode.Length >= 18 ? sTypeCollCode.Substring(0, 18) : "";//户籍 ddlSheng_SelectedIndexChanged(this.ddlPlaceSheng, new EventArgs()); this.ddlPlaceCity.SelectedValue = sTypeCollCode.Length >= 27 ? sTypeCollCode.Substring(0, 27) : "";//户籍 ddlSheng_SelectedIndexChanged(this.ddlPlaceCity, new EventArgs()); this.ddlPlaceArea.SelectedValue = sTypeCollCode;//户籍 } else if (mTypeList.Count > 1) { this.LabelCheckCardMsg.Text = "身份证号未唯一匹配到区域"; return; } else { this.LabelCheckCardMsg.Text = "身份证号未匹配到区域"; return; } //通过截取身份证号计算年龄 string sAge = s.Substring(6, 4); try { tbStuAge.Text = (DateTime.Now.Year - Convert.ToInt32(sAge)).ToString(); } catch { this.LabelCheckCardMsg.Text = "身份证号输入错误"; return; } }