1、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
2、 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 联动代码如下:
3、1>户籍所在
7、 2009-09-09 22:09:40 asp二级联动同个表 分类:(asp编程) | 评论:(0) | 浏览:(137) | 标签: 二级联动 同个表 数据库结构 程序代码 id anclassid anclass nclass 0 0 一年级 一年五班 1 1 二年级 二年二班
8、 2 0 一年级 一年二班 3 1 二年级 二年一班 4 1 二年级 二年三班 5 2 三年级
9、 三年一班 6 2 三年级 三年二班 7 2 三年级 三年三班 <% dim conn,constr constr="driver={microsoft access driver (*.mdb)};uid=admin;pwd=数据库密码;dbq="&
10、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%> <% 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
16、 else %>
Asp.Net DataGrid控件分页代码 2008-08-21 18:23 先看实现的效果: 代码: <% @ Page Language="C#" %> <% @ Import Namespace="System.Data" %> <% @ Import Namespace="System.Data.OleDb" %>28、
33、p="true" CodeFile="PageGridView.aspx.cs" Inherits="PageGridView" %>
34、tent="javascript" name="vs_defaultClientScript">
cs.文件 using System; using System.Collections; using System.ComponentModel; using System.Data; usi39、ng 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 pageCou
40、nt; protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { DataGridDataBind(); } } //绑定数据 private void DataGridDataBind() { DataSet ds = GetCustomersData(); recordCount = ds.Tables[0].Row
41、s.Count; //获取当前的页数 pageCount = (int)Math.Ceiling(recordCount * 1.0 / PageSize); //避免纪录从有到无时,并且已经进行过反页的情况下CurrentPageIndex > PageCount出错 if (recordCount == 0) { this.DataGrid1.CurrentPageIndex = 0; } else if (this.DataGrid1
42、CurrentPageIndex >= pageCount) { this.DataGrid1.CurrentPageIndex = pageCount - 1; } this.DataGrid1.DataSource = ds; this.DataGrid1.DataBind(); NavigationStateChange(); } #region Web 窗体设计器生成的代码 override protected void OnInit(Ev
43、entArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
///
44、 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.EventHand
45、ler(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) {
46、 case "First": PageIndex = 0; break; case "Prev"://if( PageIndex > 0 ) PageIndex = PageIndex - 1; break; case "Next"://if( PageIndex < PageCount -1) PageIndex = PageIndex + 1;
47、 break; case "Last": PageIndex = PageCount - 1; break; } DataGridDataBind(); } //数据绑定 public static DataSet GetCustomersData() { SqlConnection conn = new SqlConnection("server=.;database=NorthWind;u
48、id=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);
49、 return ds;
}
///






