收藏 分销(赏)

asp中的省市二级联动.doc

上传人:pc****0 文档编号:7442194 上传时间:2025-01-04 格式:DOC 页数:29 大小:162KB 下载积分:10 金币
下载 相关 举报
asp中的省市二级联动.doc_第1页
第1页 / 共29页
asp中的省市二级联动.doc_第2页
第2页 / 共29页


点击查看更多>>
资源描述
asp中的省市二级联动(2008-11-27 22:26:05) 标签:it  分类:asp sql server下的自建表 province(省份),city(城市),如下:                    省份表province  province_id province_name  ProvinceNo   ProvinceOrder  1  北京市  1  1  2  上海市  2  2  3  黑龙江省  3  3  4  吉林省  4  4                      城市表city   city_id   city_name  CityNo CityOrder  province_id   1  东城区  1  1  1  2  哈尔滨  2  2  3  3  佳木斯  3  3  3  4  黄浦区  4  4  2  5  长春市  5  5  4   联动代码如下: <!--//////////////////////////Province_select下拉列表//////////////////////////--> <TR bgColor=#ffffff> <TD><FONT size=-1><B>户籍所在</B></FONT></TD> <TD width="40%"><FONT size=-1><LABEL for=as_vt>搜索户籍所在地满足条件的用户</LABEL></FONT></TD> <TD> <select name="province_select" onChange=chsel()> <option value="xxx" selected>请选择省份……</option> <% dim tmpid '定义一个临时变量用来记住省id tmpid=0 set rs_Province=server.CreateObject("ADODB.recordset") sql="select * from province order by ProvinceOrder" rs_Province.open sql,conn,1,1 while not rs_Province.eof tmpid=rs_Province("province_id") %> <option value="<%=rs_Province("province_id")%>" ><%=trim(rs_Province("province_name"))%></option> <% rs_Province.movenext wend rs_Province.close set rs_Province=nothing %> </select> <!--//////////////////////////City_select下拉列表//////////////////////////--> <select name="city_select"> <option value="xxx" selected>请选择城市……</option> <% set rs_City=server.createobject("adodb.recordset") sql="select * from city where province_id="&tmpid&" order by CityOrder" rs_City.open sql,conn,1,1 while not rs_City.eof %> <option value="<%=rs_City("city_id")%>"><%=trim(rs_City("city_name"))%></option> <% rs_City.movenext wend rs_City.close set rs_City=nothing %> </select> </TD></TR> 2009-09-09 22:09:40 asp二级联动同个表 分类:(asp编程) | 评论:(0) | 浏览:(137) | 标签: 二级联动 同个表 数据库结构 程序代码   id   anclassid     anclass             nclass     0           0               一年级             一年五班                             1           1               二年级             二年二班                             2           0               一年级             一年二班                             3           1               二年级             二年一班                             4           1               二年级             二年三班                             5           2               三年级             三年一班                             6           2               三年级             三年二班                             7           2               三年级             三年三班      <%          dim   conn,constr        constr="driver={microsoft   access   driver   (*.mdb)};uid=admin;pwd=数据库密码;dbq="&   server.mappath("class.mdb")        set   conn=server.createobject("adodb.connection")          conn.open   constr               set   rs=server.createobject("adodb.recordset")        rs.open   "select   *   from   school   order   by   anclassid",conn,1,1%>        <script   language   =   "JavaScript">        var   onecount;        onecount=0;        subcat   =   new   Array();        <%              count   =   0              do   while   not   rs.eof          %>        subcat[<%=count%>]   =   new   Array("<%=   trim(rs("anclassid"))%>","<%=   rs("anclass")%>","<%=   rs("nclass")%>");        <%                        countcount   =   count   +   1                        rs.movenext                        loop                        rs.close        %>               onecount=<%=count%>;               function   changelocation(locationid)                {                document.form.Nclassid.length   =   0;                         var   locationidlocationid=locationid;                var   i;                for   (i=0;i   <   onecount;   i++)                        {                                if   (subcat[i][0]   ==   locationid)                                {                                    document.form.Nclassid.options[document.form.Nclassid.length]   =   new   Option(subcat[i][2],   subcat[i][2]);   //这里图像的内容已[ 2 ]                             }                                        }                                       }                </script>        <%        set   rs=server.createobject("adodb.recordset")        rs.open   "select   distinct   anclassid,anclass   from   school   order   by   anclassid",conn,1,1        if   rs.eof   and   rs.bof   then        response.write   "请先添加栏目。"        response.end        else        %>        <form   name="form">        <select   name="anclassid"   size="1"   id="class"   onChange="changelocation(document.form.anclassid.value)">        <option   selected   value="<%=rs("anclassid")%>"><%=trim(rs("anclass"))%></option>        <%   dim   selclass                          selclass=rs("anclassid")                        rs.movenext                        do   while   not   rs.eof        %>          <option   value="<%=rs("anclassid")%>"><%=trim(rs("anclass"))%></option>        <%                        rs.movenext                        loop        end   if                        rs.close        %>          </select>        <select   name="Nclassid">          <%rs.open   "select   *   from   school   where   anclassid="&selclass   ,conn,1,1        if   not(rs.eof   and   rs.bof)   then        %>            <option   selected   value="<%=rs("nclass")%>"><%=rs("nclass")%></option>          <%   rs.movenext        do   while   not   rs.eof%>          <option   value="<%=rs("nclass")%>"><%=rs("nclass")%></option>        <%   rs.movenext        loop        end   if                        rs.close                        set   rs   =   nothing        %>            </select>          </form>     Asp.Net DataGrid控件分页代码 2008-08-21 18:23 先看实现的效果: 代码: <% @ Page Language="C#" %> <% @ Import Namespace="System.Data" %> <% @ Import Namespace="System.Data.OleDb" %> <script language="C#" runat="Server"> private int recordCount; public void Page_Load(Object src,EventArgs e) {     string strComm = "select * from news"; string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=";      strConnection += Server.MapPath("app_data/data.mdb");      OleDbConnection MyConnection = new OleDbConnection(strConnection); OleDbDataAdapter MyComm = new OleDbDataAdapter(strComm, MyConnection); DataSet MyDataSet = new DataSet(); MyComm.Fill(MyDataSet,"UserList"); recordCount = MyDataSet.Tables[0].Rows.Count; DataGrid1.DataSource = MyDataSet.Tables["UserList"].DefaultView; if(!Page.IsPostBack) {    DataGrid1.DataBind();    pagecount.Text = DataGrid1.PageCount.ToString();    nowpage.Text = "1";    pagesize.Text = DataGrid1.PageSize.ToString();    _recordCount.Text = recordCount.ToString(); } } private void change_page(object sender, System.EventArgs e) {     LinkButton btn = (LinkButton)sender;     int PageIndex = Int32.Parse(nowpage.Text) - 1;     int _pagecount = Int32.Parse(pagecount.Text);     switch(btn.CommandName)     {         case "First":             PageIndex = 0;             break;         case "Prev":             PageIndex = PageIndex - 1;             break;         case "Next":             PageIndex = PageIndex + 1;             break;         case "Last":             PageIndex = _pagecount-1;             break;     }     if(PageIndex < 0)         PageIndex = 0;     else if (PageIndex > _pagecount-1)         PageIndex = _pagecount-1;             DataGrid1.CurrentPageIndex = PageIndex;     DataGrid1.DataBind(); pagecount.Text = DataGrid1.PageCount.ToString(); nowpage.Text = (DataGrid1.CurrentPageIndex + 1).ToString(); pagesize.Text = DataGrid1.PageSize.ToString(); _recordCount.Text = recordCount.ToString(); } public void DataGrid1_PageIndexChanged(object sender,DataGridPageChangedEventArgs e)   {   //startIndex = e.NewPageIndex*DataGrid1.PageSize;   DataGrid1.CurrentPageIndex=e.NewPageIndex;   DataGrid1.DataBind(); } </script> <html> <head>     <title>Asp.Net分页学习</title> </head> <body> <form id="Form1" method="post" runat="server">     <asp:DataGrid ID="DataGrid1" ShowHeader="false" AutoGenerateColumns="false" runat="server"         PageSize="5" Width="100%" AllowPaging="True" HeaderStyle-Wrap="False">         <HeaderStyle Font-Size="9pt"></HeaderStyle>         <FooterStyle Font-Size="9pt"></FooterStyle>         <PagerStyle Visible="False" Font-Size="9pt" Mode="NumericPages"></PagerStyle>         <Columns>             <asp:BoundColumn DataField="new_id" />             <asp:BoundColumn DataField="new_title" />             <asp:BoundColumn DataField="new_time" />         </Columns>     </asp:DataGrid>     <asp:LinkButton ID="LBtnFirst" runat="server" CommandName="First" OnClick="change_page">首页</asp:LinkButton>     <asp:LinkButton ID="LBtnPrev" runat="server" CommandName="Prev" OnClick="change_page">上一页</asp:LinkButton>     <asp:LinkButton ID="LBtnNext" runat="server" CommandName="Next" OnClick="change_page">下一页</asp:LinkButton>     <asp:LinkButton ID="LBtnLast" runat="server" CommandName="Last" OnClick="change_page">尾页</asp:LinkButton>         第<asp:Literal ID="nowpage" runat="server"></asp:Literal>页     共<asp:Literal ID="pagecount" runat="server"></asp:Literal>页     每页<asp:Literal ID="pagesize" runat="server"></asp:Literal>条     共<asp:Literal ID="_recordCount" runat="server"></asp:Literal>条 </form> </body> </html> DataGrid自带分页实现 2008-08-05 16:45 webForm.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeFile="PageGridView.aspx.cs" Inherits="PageGridView" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML> <HEAD> <title>DataGridPaging</title> <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR"> <meta content="C#" name="CODE_LANGUAGE"> <meta content="javascript" name="vs_defaultClientScript"> <meta content=" name="vs_targetSchema"> </HEAD> <body> <form id="Form1" method="post" runat="server"> <TABLE id="Table1" style="FONT-SIZE: 9pt" cellSpacing="1" cellPadding="1" width="450" align="center" border="1"> <TR> <TD><ASP:datagrid id="DataGrid1" runat="server" PageSize="5" Width="100%" AllowPaging="True"> <HeaderStyle Font-Size="9pt"></HeaderStyle> <FooterStyle Font-Size="9pt"></FooterStyle> <PagerStyle Visible="False" Font-Size="9pt" Mode="NumericPages"></PagerStyle> </ASP:datagrid></TD> </TR> </TABLE> <TABLE id="Table2" style="FONT-SIZE: 9pt" cellSpacing="1" cellPadding="1" width="450" align="center" border="1"> <TR> <TD style="WIDTH: 207px"> <ASP:linkbutton id="LBtnFirst" runat="server" CommandName="First">首页</ASP:linkbutton> <ASP:linkbutton id="LBtnPrev" runat="server" CommandName="Prev">上一页</ASP:linkbutton> <ASP:linkbutton id="LBtnNext" runat="server" CommandName="Next">下一页</ASP:linkbutton> <ASP:linkbutton id="LBtnLast" runat="server" CommandName="Last">尾页</ASP:linkbutton> </TD> <TD>第 <ASP:literal id="LtlPageIndex" runat="server"></ASP:literal>页 共 <ASP:literal id="LtlPageCount" runat="server"></ASP:literal>页 每页 <ASP:literal id="LtlPageSize" runat="server"></ASP:literal>条 共 <ASP:literal id="LtlRecordCount" runat="server"></ASP:literal>条 </TD> </TR> </TABLE> </form> </body> </HTML> cs.文件 using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Configuration; public partial class PageGridView : System.Web.UI.Page {     private int recordCount;     private int pageCount;     protected void Page_Load(object sender, EventArgs e)     {         if (!Page.IsPostBack)         {             DataGridDataBind();         }     }     //绑定数据     private void DataGridDataBind()     {         DataSet ds = GetCustomersData();         recordCount = ds.Tables[0].Rows.Count;         //获取当前的页数         pageCount = (int)Math.Ceiling(recordCount * 1.0 / PageSize);         //避免纪录从有到无时,并且已经进行过反页的情况下CurrentPageIndex > PageCount出错         if (recordCount == 0)         {             this.DataGrid1.CurrentPageIndex = 0;         }         else if (this.DataGrid1.CurrentPageIndex >= pageCount)         {             this.DataGrid1.CurrentPageIndex = pageCount - 1;         }         this.DataGrid1.DataSource = ds;         this.DataGrid1.DataBind();         NavigationStateChange();     }     #region Web 窗体设计器生成的代码     override protected void OnInit(EventArgs e)     {         //         // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。         //         InitializeComponent();         base.OnInit(e);     }     /// <summary>     /// 设计器支持所需的方法 - 不要使用代码编辑器修改     /// 此方法的内容。     /// </summary>     private void InitializeComponent()     {         this.LBtnFirst.Click += new System.EventHandler(this.LBtnNavigation_Click);         this.LBtnPrev.Click += new System.EventHandler(this.LBtnNavigation_Click);         this.LBtnNext.Click += new System.EventHandler(this.LBtnNavigation_Click);         this.LBtnLast.Click += new System.EventHandler(this.LBtnNavigation_Click);         this.Load += new System.EventHandler(this.Page_Load);     }     #endregion     private void LBtnNavigation_Click(object sender, System.EventArgs e)     {         LinkButton btn = (LinkButton)sender;         switch (btn.CommandName)         {             case "First":                 PageIndex = 0;                 break;             case "Prev"://if( PageIndex > 0 )                 PageIndex = PageIndex - 1;                 break;             case "Next"://if( PageIndex < PageCount -1)                 PageIndex = PageIndex + 1;                 break;             case "Last":                 PageIndex = PageCount - 1;                 break;         }         DataGridDataBind();     }     //数据绑定     public static DataSet GetCustomersData()     {         SqlConnection conn = new SqlConnection("server=.;database=NorthWind;uid=sa;pwd=sa;");         string sqlStr = "SELECT CustomerID, CompanyName,Address,Phone FROM Customers";         SqlCommand comm = new SqlCommand(sqlStr, conn);         SqlDataAdapter dataAdapter = new SqlDataAdapter(comm);         DataSet ds = new DataSet();         dataAdapter.Fill(ds);         return ds;     }     /// <summary>     /// 控制导航按钮或数字的状态     /// </summary>     public void NavigationStateChange()     {         if (PageCount <= 1)//( RecordCount <= PageSize )//小于等于一页         {             this.LBtnFirst.Enabled = false;             this.LBtnPrev.Enabled = false;             this.LBtnNext.Enabled = false;             this.LBtnLast.Enabled = false;         }         else //有多页         {             if (PageIndex == 0)//当前为第一页             {                 this.LBtnFirst.Enabled = false;                
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 百科休闲 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服