namespace webapplicationdlh
{
using system;
using system.data;
using system.drawing;
using system.web;
using system.web.ui.webcontrols;
using system.web.ui.htmlcontrols;
using system.data.sqlclient;
using db;
/// <summary>
/// area 的摘要说明。
/// </summary>
public class area : system.web.ui.usercontrol
{
protected system.web.ui.webcontrols.dropdownlist ddlprovince;
protected system.web.ui.webcontrols.dropdownlist ddlcity;
public string strprovince
{
get
{
return ddlprovince.selecteditem.value;
}
set
{
ddlprovince.selecteditem.value = value;
}
}
public string strcity
{
get
{
return ddlcity.selecteditem.value;
}
set
{
ddlcity.selecteditem.value = value;
}
}
private void page_load(object sender, system.eventargs e)
{
if(!ispostback)
{
ddlprovincebind();
ddlcity.items.insert(0,"-请选择城市-");
}
}
private void ddlprovincebind()
{
db.area myarea = new db.area();
sqldatareader dr = myarea.getallprovince();
if(dr.read())
{
ddlprovince.datasource = dr;
ddlprovince.datatextfield = "province";
ddlprovince.datavaluefield = "province";
ddlprovince.databind();
ddlprovince.items.insert(0,"-请选择省份-");
}
}
#region web 窗体设计器生成的代码
override protected void oninit(eventargs e)
{
//
// codegen: 该调用是 asp.net web 窗体设计器所必需的。
//
initializecomponent();
base.oninit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void initializecomponent()
{
this.ddlprovince.selectedindexchanged += new system.eventhandler(this.ddlprovince_selectedindexchanged);
this.load += new system.eventhandler(this.page_load);
}
#endregion
private void ddlprovince_selectedindexchanged(object sender, system.eventargs e)
{
if(ddlprovince.selecteditem.value == "-请选择省份-")
{
ddlcity.items.clear();
ddlcity.items.insert(ddlprovince.selectedindex,"-请选择城市-");
}
else
{
db.area myarea = new db.area();
sqldatareader dr = myarea.getallcitywhereprovince(ddlprovince.selecteditem.value);
if(dr.read())
{
ddlcity.datasource = dr;
ddlcity.datatextfield = "city";
ddlcity.datavaluefield = "id";
ddlcity.databind();
}
}
}
}
}
=============================================================〉
using system;
using system.data;
using system.data.sqlclient;
using system.configuration;
namespace db
{
/// <summary>
/// area 的摘要说明。
/// </summary>
public class area:base
{
public area()
{
//
// todo: 在此处添加构造函数逻辑
//
}
public sqldatareader getallprovince()
{
strsp = "sp_area_selectall";
drselectall(strsp);
return dr;
}
public sqldatareader getallcitywhereprovince(string a)
{
conn = new sqlconnection(configurationsettings.appsettings["dsn"]);
cmd = new sqlcommand("sp_area_selectallwhereprovince",conn);
cmd.commandtype = commandtype.storedprocedure;
cmd.parameters.add("@province",sqldbtype.varchar,50).value = a.tostring();
conn.open();
dr = cmd.executereader(commandbehavior.closeconnection);
return dr;
}
}
}
=====================================================〉
if exists (select * from dbo.sysobjects where id = object_id(n’[dbo].[sp_area_selectall]’) and objectproperty(id, n’isprocedure’) = 1)
drop procedure [dbo].[sp_area_selectall]
go
if exists (select * from dbo.sysobjects where id = object_id(n’[dbo].[sp_area_selectallwhereprovince]’) and objectproperty(id, n’isprocedure’) = 1)
drop procedure [dbo].[sp_area_selectallwhereprovince]
go
if exists (select * from dbo.sysobjects where id = object_id(n’[dbo].[area]’) and objectproperty(id, n’isusertable’) = 1)
drop table [dbo].[area]
go
create table [dbo].[area] (
[id] [int] not null ,
[province] [varchar] (50) collate chinese_prc_ci_as null ,
[city] [varchar] (50) collate chinese_prc_ci_as null ,
[其它] [varchar] (50) collate chinese_prc_ci_as null
) on [primary]
go
set quoted_identifier on
go
set ansi_nulls on
go
create procedure sp_area_selectall
as
select distinct province
from area
order by province
return
go
set quoted_identifier off
go
set ansi_nulls on
go
set quoted_identifier on
go
set ansi_nulls on
go
create procedure sp_area_selectallwhereprovince
@province varchar(50)
as
select area.*
from area
where (province = @province)
return
go
set quoted_identifier off
go
set ansi_nulls on
go
================================================〉
using system;
using system.data;
using system.data.sqlclient;
using system.configuration; namespace db
{
/// <summary>
/// base 的摘要说明。
/// </summary>
public class base
{
public base()
{
//
// todo: 在此处添加构造函数逻辑
//
}
protected string con = configurationsettings.appsettings["dsn"];
protected sqlconnection conn;
protected sqlcommand cmd;
protected sqldatareader dr;
protected string strsp;
protected sqldatareader drselectall(string strsp)
{
conn = new sqlconnection(con);
cmd = new sqlcommand(strsp,conn);
cmd.commandtype = commandtype.storedprocedure; conn.open();
dr = cmd.executereader(commandbehavior.closeconnection);
return dr;
}//返回一个sqldatareader }
}
最大的网站源码资源下载站,
新闻热点
疑难解答
图片精选