一公3个文件和3个存储过程 文章长了点 请大家帮我ET_DB.cs--------
using System;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;namespace ASP_ET
{
/// <summary>
/// ET_DB 的摘要说明。
/// </summary>
public class ET_DB
{
public ET_DB()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public SqlConnection GetConnection()
{
SqlConnection myConnection = new SqlConnection("server=127.0.0.1;integrated security=sspi;initial catalog=mm");
return myConnection;
} public SqlDataReader GetReader(string strsql)
{
SqlConnection conn = GetConnection();
conn.Open();
SqlCommand sqlcmd = new SqlCommand(strsql, conn);
return sqlcmd.ExecuteReader();
} public DataSet GetDataSet(string strsql)
{
DataSet ds = new DataSet();
SqlDataAdapter ada = new SqlDataAdapter(strsql, GetConnection());
ada.Fill(ds);
return ds;
}
}
}*.aspx
-------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ld.aspx.cs" Inherits="ld" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<asp:DropDownList id="ClassID" runat="server" onChange="changelocation(document.Form1.ClassID.options[document.Form1.ClassID.selectedIndex].value)"></asp:DropDownList>
<asp:DropDownList id="NclassID" runat="server"></asp:DropDownList>
<asp:Button id="Button1" runat="server" Text="Button" OnClick="Button1_Click1" EnableTheming="True"></asp:Button>
</form>
</body>
</html>
----------------
*.asp.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.Web.UI.HtmlControls;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;public partial class ld : System.Web.UI.Page
{
ASP_ET.ET_DB ET_DB = new ASP_ET.ET_DB();
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataBinds();
ReWriteScript();
}
}
private void ReWriteScript()
{
int count = 0;
string scriptString = "<Script Language=JavaScript>\n var onecount;";
scriptString += "\nonecount=0;";
scriptString += "\nsubcat=new Array();";
SqlDataReader rs = this.GetNclass();
while (rs.Read())
{
scriptString += "\n subcat[" + count + "]=new Array(" + "'" + rs["Nclass"] + "'" + "," + "'" + rs["classID"] + "'" + "," + "'" + rs["NclassID"] + "'" + ");";
count++;
}
rs.Close();
scriptString += "\n onecount=" + count + ";";
scriptString += "\n function changelocation(locationid){";
scriptString += "\n document.Form1.NclassID.length = 0;";
scriptString += "\n var locationid=locationid;";
scriptString += "\n var i;";
scriptString += "\n for(i=0; i<onecount; i++){";
scriptString += "\n if(subcat[i][1]==locationid){";
scriptString += "\n document.Form1.NclassID.options[document.Form1.NclassID.length]=new Option(subcat[i][0],subcat[i][2]);";
scriptString += "\n }";
scriptString += "\n }";
scriptString += "\n }";
scriptString += "<";
scriptString += "/";
scriptString += "script>";
if (!this.IsClientScriptBlockRegistered("clientScript"))
{
this.RegisterClientScriptBlock("clientScript", scriptString);
}
} private SqlDataReader GetNclass()
{
SqlDataReader NclassReader = SqlHelper.ExecuteReader(ET_DB.GetConnection(), CommandType.StoredProcedure, "sp_News_GetNClass");
return NclassReader;
}
private DataSet Getclass()
{
DataSet Classds = SqlHelper.ExecuteDataset(ET_DB.GetConnection(), CommandType.StoredProcedure, "sp_News_GetClass");
return Classds;
}
private DataSet Getnclass()
{
DataSet Classds = SqlHelper.ExecuteDataset(ET_DB.GetConnection(), CommandType.StoredProcedure, "sp_News_GetNClass");
return Classds;
}
private DataSet Getnclass(int classid)
{
SqlParameter[] parameter ={ new SqlParameter("@ClassID", SqlDbType.Int, 4) };
parameter[0].Value = classid;
using (DataSet ds = SqlHelper.ExecuteDataset(ET_DB.GetConnection(), CommandType.StoredProcedure, "Sp_News_GetNclassBYclassID", parameter))
{
return ds;
}
}
private void DataBinds()
{
DataTable dt = this.Getclass().Tables[0]; //获得大类列表 this.ClassID.DataSource = dt;
this.ClassID.DataTextField = "ClassName";
this.ClassID.DataValueField = "ClassID";
this.ClassID.DataBind();
DataTable dtn = Getnclass(int.Parse(this.ClassID.SelectedValue)).Tables[0]; //根据大类列表默认选中项读出所属的小类列表
this.NclassID.DataSource = dtn;
this.NclassID.DataTextField = "Nclass";
this.NclassID.DataValueField = "NclassID";
this.NclassID.DataBind(); } private void Button1_Click(object sender, System.EventArgs e)
{
}
protected void Button1_Click1(object sender, EventArgs e)
{
//Response.Write();
//Response.Write("</br>");
//Response.Write();
Response.Redirect("open.aspx?id=" + Request.Params[1] + "&pwd=" + Request.Params[2]);
}
}
例子的数据库表结构如下
News_Anclass←表名nclassid naclass classid ←字段名News_Aclass←表名classid classname ←字段名我自己的数据库结构如下
diqu←表名bh diquname←字段名
diqu_cj←表名
bh cjname diqulei ←字段名
存储过程肯定没错我就不贴了。 好象就是aspx.cs中的javascript中列名的问题
using System;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;namespace ASP_ET
{
/// <summary>
/// ET_DB 的摘要说明。
/// </summary>
public class ET_DB
{
public ET_DB()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public SqlConnection GetConnection()
{
SqlConnection myConnection = new SqlConnection("server=127.0.0.1;integrated security=sspi;initial catalog=mm");
return myConnection;
} public SqlDataReader GetReader(string strsql)
{
SqlConnection conn = GetConnection();
conn.Open();
SqlCommand sqlcmd = new SqlCommand(strsql, conn);
return sqlcmd.ExecuteReader();
} public DataSet GetDataSet(string strsql)
{
DataSet ds = new DataSet();
SqlDataAdapter ada = new SqlDataAdapter(strsql, GetConnection());
ada.Fill(ds);
return ds;
}
}
}*.aspx
-------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ld.aspx.cs" Inherits="ld" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<asp:DropDownList id="ClassID" runat="server" onChange="changelocation(document.Form1.ClassID.options[document.Form1.ClassID.selectedIndex].value)"></asp:DropDownList>
<asp:DropDownList id="NclassID" runat="server"></asp:DropDownList>
<asp:Button id="Button1" runat="server" Text="Button" OnClick="Button1_Click1" EnableTheming="True"></asp:Button>
</form>
</body>
</html>
----------------
*.asp.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.Web.UI.HtmlControls;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;public partial class ld : System.Web.UI.Page
{
ASP_ET.ET_DB ET_DB = new ASP_ET.ET_DB();
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataBinds();
ReWriteScript();
}
}
private void ReWriteScript()
{
int count = 0;
string scriptString = "<Script Language=JavaScript>\n var onecount;";
scriptString += "\nonecount=0;";
scriptString += "\nsubcat=new Array();";
SqlDataReader rs = this.GetNclass();
while (rs.Read())
{
scriptString += "\n subcat[" + count + "]=new Array(" + "'" + rs["Nclass"] + "'" + "," + "'" + rs["classID"] + "'" + "," + "'" + rs["NclassID"] + "'" + ");";
count++;
}
rs.Close();
scriptString += "\n onecount=" + count + ";";
scriptString += "\n function changelocation(locationid){";
scriptString += "\n document.Form1.NclassID.length = 0;";
scriptString += "\n var locationid=locationid;";
scriptString += "\n var i;";
scriptString += "\n for(i=0; i<onecount; i++){";
scriptString += "\n if(subcat[i][1]==locationid){";
scriptString += "\n document.Form1.NclassID.options[document.Form1.NclassID.length]=new Option(subcat[i][0],subcat[i][2]);";
scriptString += "\n }";
scriptString += "\n }";
scriptString += "\n }";
scriptString += "<";
scriptString += "/";
scriptString += "script>";
if (!this.IsClientScriptBlockRegistered("clientScript"))
{
this.RegisterClientScriptBlock("clientScript", scriptString);
}
} private SqlDataReader GetNclass()
{
SqlDataReader NclassReader = SqlHelper.ExecuteReader(ET_DB.GetConnection(), CommandType.StoredProcedure, "sp_News_GetNClass");
return NclassReader;
}
private DataSet Getclass()
{
DataSet Classds = SqlHelper.ExecuteDataset(ET_DB.GetConnection(), CommandType.StoredProcedure, "sp_News_GetClass");
return Classds;
}
private DataSet Getnclass()
{
DataSet Classds = SqlHelper.ExecuteDataset(ET_DB.GetConnection(), CommandType.StoredProcedure, "sp_News_GetNClass");
return Classds;
}
private DataSet Getnclass(int classid)
{
SqlParameter[] parameter ={ new SqlParameter("@ClassID", SqlDbType.Int, 4) };
parameter[0].Value = classid;
using (DataSet ds = SqlHelper.ExecuteDataset(ET_DB.GetConnection(), CommandType.StoredProcedure, "Sp_News_GetNclassBYclassID", parameter))
{
return ds;
}
}
private void DataBinds()
{
DataTable dt = this.Getclass().Tables[0]; //获得大类列表 this.ClassID.DataSource = dt;
this.ClassID.DataTextField = "ClassName";
this.ClassID.DataValueField = "ClassID";
this.ClassID.DataBind();
DataTable dtn = Getnclass(int.Parse(this.ClassID.SelectedValue)).Tables[0]; //根据大类列表默认选中项读出所属的小类列表
this.NclassID.DataSource = dtn;
this.NclassID.DataTextField = "Nclass";
this.NclassID.DataValueField = "NclassID";
this.NclassID.DataBind(); } private void Button1_Click(object sender, System.EventArgs e)
{
}
protected void Button1_Click1(object sender, EventArgs e)
{
//Response.Write();
//Response.Write("</br>");
//Response.Write();
Response.Redirect("open.aspx?id=" + Request.Params[1] + "&pwd=" + Request.Params[2]);
}
}
例子的数据库表结构如下
News_Anclass←表名nclassid naclass classid ←字段名News_Aclass←表名classid classname ←字段名我自己的数据库结构如下
diqu←表名bh diquname←字段名
diqu_cj←表名
bh cjname diqulei ←字段名
存储过程肯定没错我就不贴了。 好象就是aspx.cs中的javascript中列名的问题
解决方案 »
- Word文档MailMerge之后怎样赋予新名字?
- 如何读取一个cookies 的过期时间以秒为单位。
- 求HyperLink控件高手解脱
- 新闻发布系统中文章有大类和小类,大类和小类基本上是不变的,怎么维护大类和小类管理,易于以后大类小类的维护,怎么让小类和下面的文章关联
- 当textbox的type=password的时候问题
- 高分请教一个很伤脑筋的问题
- 找不到错误了,我晕啊~~~是不是不能这么写的啊?
- ~~我行表头和列表头 都写在数组里,然后绑定在datagrid上.在页面上datagrid能显示出我查询的所有信息.....
- rebuild和build
- 后台获取动态生成的HTML控件Textarea的输入在文本框中的内容
- 谁来解释解释一下这段代码?
- 关于读取文件的问题(急救啊!)
http://blog.csdn.net/hchxxzx/archive/2005/07/01/409158.aspx