搜档网
当前位置:搜档网 › asp中的省市二级联动

asp中的省市二级联动

asp中的省市二级联动(2008-11-27 22:26:05)

标签:it分类:asp sql server下的自建表 province(省份),city(城市),如下:

城市表city

联动代码如下:

户籍所在

for=as_vt>搜索户籍所在地满足条件的用户

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

<%

set rs=server.createobject("adodb.recordset")

rs.open "select distinct anclassid,anclass from school orde r by anclassid",conn,1,1

if rs.eof and rs.bof then

response.write "请先添加栏目。"

response.end

else

%>

https://www.sodocs.net/doc/be9622740.html, DataGrid控件分页代码

2008-08-21 18:23

先看实现的效果:

代码:

<% @ Page Language="C#" %>

<% @ Import Namespace="System.Data" %>

<% @ Import Namespace="System.Data.OleDb" %>

https://www.sodocs.net/doc/be9622740.html,分页学习

PageSize="5" Width="100%" AllowPaging="True"

HeaderStyle-Wrap="False">

Mode="NumericPages">

首页

上一页

下一页

尾页

每页

DataGrid自带分页实现

2008-08-05 16:45

webForm.aspx

<%@ Page Language="C#" AutoEventWireup="true"

CodeFile="PageGridView.aspx.cs" Inherits="PageGridView" %>

DataGridPaging

border="1">

Width="100%" AllowPaging="True">

Mode="NumericPages">

border="1">

首页

上一页

下一页

尾页

页共

页每页

条共

cs.文件

using System;

using System.Collections;

using https://www.sodocs.net/doc/be9622740.html,ponentModel;

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: 该调用是 https://www.sodocs.net/doc/be9622740.html, Web 窗体设计器所必需的。 //

InitializeComponent();

base.OnInit(e);

}

///

/// 设计器支持所需的方法 - 不要使用代码编辑器修改

/// 此方法的内容。

///

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 (https://www.sodocs.net/doc/be9622740.html,mandName)

{

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;

}

///

/// 控制导航按钮或数字的状态

///

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;

this.LBtnPrev.Enabled = false;

this.LBtnNext.Enabled = true;

this.LBtnLast.Enabled = true;

}

else if (PageIndex == PageCount - 1)//当前为最后页

{

this.LBtnFirst.Enabled = true;

this.LBtnPrev.Enabled = true;

this.LBtnNext.Enabled = false;

this.LBtnLast.Enabled = false;

}

else //中间页

{

this.LBtnFirst.Enabled = true;

this.LBtnPrev.Enabled = true;

this.LBtnNext.Enabled = true;

this.LBtnLast.Enabled = true;

}

}

if (RecordCount == 0)//当没有纪录时DataGrid.PageCount会显示1页

this.LtlPageCount.Text = "0";

else

this.LtlPageCount.Text = PageCount.ToString();

if (RecordCount == 0)

this.LtlPageIndex.Text = "0";

else

this.LtlPageIndex.Text = (PageIndex + 1).ToString();//在有页数的情况下前台显示页数加1

this.LtlPageSize.Text = PageSize.ToString();

this.LtlRecordCount.Text = RecordCount.ToString();

}

// 总页数

public int PageCount

{

get { return this.DataGrid1.PageCount; }

}

//页大小

public int PageSize

{

get { return this.DataGrid1.PageSize; }

}

//页索引,从零开始

public int PageIndex

{

get { return this.DataGrid1.CurrentPageIndex; }

set { this.DataGrid1.CurrentPageIndex = value; }

}

// 纪录总数

public int RecordCount

{

get { return recordCount; }

set { recordCount = value; }

}

}

DataGrid快速分页

2009-07-27 11:06

cs:

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Data.SqlClient;

public partial class user_shiyan2 : System.Web.UI.Page

{

private static int intRecordCount; //记录总数

private static int intPageCount; //总页数 private static int intCurrentPageIndex; //当前页码

private DataView dv;

protected void Page_Load(object sender, EventArgs e)

{

if (!Page.IsPostBack)

{

//将当前页面置为1,即显示第一页的记录

intCurrentPageIndex = 1;

//设置属性

// DataGrid1.AllowPaging = "True";

DataGrid1.AllowPaging = true;

// DataGrid1AllowCustomPaging = "True";

DataGrid1.AllowCustomPaging = true;

//绑定数据(Bind()是一个自定义方法)

this.Bind(intCurrentPageIndex);

}

}

private void Bind(int intCurrentPageIndex)

{

string strConn =

ConfigurationSettings.AppSettings["Str_sql"].ToString();

//每次只取出一页(即10条)数据的SQL语句

string strSql = "select top 10 * from attorn where attorn_id not in (select top " + ( intCurrentPageIndex - 1)*10 + " attorn_id from attorn)";

if (TextBox1.Text != null && TextBox1.Text != "")

{

strSql = "select top 10 * from attorn where attorn_id not in (select top " + (intCurrentPageIndex - 1) * 10 + " attorn_id from attorn where [User_name] like '%" + TextBox1.Text + "%') and [User_name] like '%" + TextBox1.Text + "%'";

}

//得到总记录数的SQL语句

string strSqlCount = "select count(*) from attorn ";

if(TextBox1.Text != null && TextBox1.Text != "")

{

strSqlCount = "select count(*) from attorn

where [User_name] like '%" + TextBox1.Text + "%'";

}

//建立与数据的连接

SqlConnection dbConnection = new SqlConnection(strConn);

dbConnection.Open();

//创建适配器的实例,并填充数据

SqlDataAdapter dsAdapter = new

SqlDataAdapter(strSql,dbConnection);

DataSet ds = new DataSet();

dsAdapter.Fill(ds);

dv = ds.Tables[0].DefaultView;

//取得总记录数

SqlCommand cmd = new SqlCommand(strSqlCount,dbConnection);

intRecordCount = (Int32) cmd.ExecuteScalar();

//关闭连接

dbConnection.Close();

//计算总页数

double dblRecordCount;

dblRecordCount = System.Convert.ToDouble(intRecordCount);

intPageCount = (Int32)Math.Ceiling(dblRecordCount / 10);

Label1.Text = intCurrentPageIndex.ToString();

Label2.Text = intPageCount.ToString();

//绑定数据

DataGrid1.DataSource = dv;

DataGrid1.DataBind();

}

protected void LinkButton1_Click(object sender, EventArgs e) {

intCurrentPageIndex = 1;

//重新绑定数据

this.Bind(intCurrentPageIndex);

}

protected void LinkButton2_Click(object sender, EventArgs e) {

intCurrentPageIndex = intCurrentPageIndex - 1;

if (intCurrentPageIndex <= 0)

{

intCurrentPageIndex = 1;

}

//重新绑定数据

this.Bind(intCurrentPageIndex);

}

protected void LinkButton3_Click(object sender, EventArgs e) {

intCurrentPageIndex = intCurrentPageIndex + 1;

if(intCurrentPageIndex > intPageCount)

{

intCurrentPageIndex = intPageCount;

}

//重新绑定数据

this.Bind(intCurrentPageIndex);

}

protected void LinkButton4_Click(object sender, EventArgs e) {

intCurrentPageIndex = intPageCount;

//重新绑定数据

this.Bind(intCurrentPageIndex);

}

protected void Button1_Click(object sender, EventArgs e)

{

intCurrentPageIndex = 1;

//重新绑定数据

this.Bind(intCurrentPageIndex);

}

}

aspx:

<%@ Page Language="C#" AutoEventWireup="true"

CodeFile="shiyan2.aspx.cs" Inherits="user_shiyan2" %>

无标题页

OnClick="LinkButton1_Click">LinkButton

OnClick="LinkButton2_Click">LinkButton

OnClick="LinkButton3_Click">LinkButton

OnClick="LinkButton4_Click">LinkButton

Text="Label">

    

Text="Label">

OnClick="Button1_Click" Text="Button" />

CheckBox放到DataGrid中对应CheckBox的列的页眉上(header).我们给这个模板列的题头上添加一个CheckBox控件利用它来完成和1中相同的工作,只是过程稍微有些不同.首先我们需要一个DataGrid来表现我们的程序,该DataGrid在Html页上的代码如下:

// 只显示主要的下面的不写了……在grdClient中有绑定的详细列

我们给HerderTemple添加了一个chkAllServer其中Server说明它是调用服务器端事件的.我们为了给这个控件添加事件必须在创建DataGridItem的时候给它添加事件代码如下:

private void grdServer_ItemCreated(object sender, System.Web.UI.WebControls.DataGridIte mEventArgs e) {

if(e.Item.ItemType == ListItemType.Header){

CheckBox chk = (CheckBox)e.Item.FindControl("chkAllServer");

相关主题