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.Web.Services;
using System.Data.SqlClient;namespace office_web
{
/// <summary>
/// product_Detail_WebForm 的摘要说明。
/// </summary>
public class product_Detail_WebForm : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button add_btn;
//定义WEB引用
protected myservice.myService WebReferences = null;
protected System.Web.UI.WebControls.DataGrid ProductDG;
protected System.Web.UI.WebControls.CheckBox chkExport;
protected System.Web.UI.WebControls.DropDownList Type_One_Text;
protected System.Web.UI.WebControls.DropDownList Type_Two_Text;
protected System.Web.UI.WebControls.DropDownList Type_Three_Text;
protected System.Web.UI.WebControls.Button Button1;
//定义数据库连接
protected SqlConnection myConnection;
//定义项目ID
protected int Project_id;
//定义配套表ID
protected int kit_id;
public string MySql;
public product_Detail_WebForm()
{
try
{
WebReferences = new myservice.myService();
}
catch { }
if (WebReferences == null)
{
// this.Response.Redirect("error.aspx?id=UnableToConnectRegisterService");
}
}
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
//得到项目ID
Project_id = int.Parse(this.Request["Project_id"].ToString());
//得到配套表ID
kit_id = int.Parse(this.Request["kit_id"].ToString());
if(!this.IsPostBack)
{
Type_One();
MySql ="select Type_Three.Type_Three_Name,Product.Product_Number,Type_Two.Type_Two_Name,Product.Product_Model_number,Product.Product_gg,Product.Product_Price,Product.Product_bit from Product,Type_Two,Type_Three where Product.Type_Three_Number=Type_Three.Type_Three_Number and Product.Type_Two_Number=Type_Two.Type_Two_Number";//SQL语句字符串
ProductDG.DataSource = product();
ProductDG.DataBind();
}
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Type_One_Text.SelectedIndexChanged += new System.EventHandler(this.Type_One_Text_SelectedIndexChanged);
this.Type_Two_Text.SelectedIndexChanged += new System.EventHandler(this.Type_Two_Text_SelectedIndexChanged);
this.Type_Three_Text.SelectedIndexChanged += new System.EventHandler(this.Type_Three_Text_SelectedIndexChanged);
this.add_btn.Click += new System.EventHandler(this.add_btn_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion #region 数据集
private DataSet product()
{
//连接数据库字符串
string ConnectionString = "Data Source="+WebReferences.strDS1()+"; Initial Catalog="+WebReferences.strDB1()+"; UID="+WebReferences.strUser1()+"; PWD="+WebReferences.strPwd1();
myConnection = new SqlConnection(ConnectionString);//建立连接
myConnection.Open();//打开连接
SqlCommand myCommand = new SqlCommand(MySql,myConnection);
SqlDataAdapter myAdapter = new SqlDataAdapter();
myAdapter.SelectCommand = myCommand;
DataSet DS = new DataSet();
myAdapter.Fill(DS);
myConnection.Close();
return DS;
}
#endregion #region 分页
public void ProductDG_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
{
//此处为分页用
ProductDG.CurrentPageIndex = e.NewPageIndex;
ProductDG.DataSource = product();
ProductDG.DataBind();
}
#endregion #region 绑定Type_One_Text数据
private void Type_One()
{
string ConnectionString = "Data Source="+WebReferences.strDS1()+"; Initial Catalog="+WebReferences.strDB1()+"; UID="+WebReferences.strUser1()+"; PWD="+WebReferences.strPwd1();
myConnection = new SqlConnection(ConnectionString);//建立连接
myConnection.Open();//打开连接
String MySql_Type_One = "select * from Type_One where Type_One_Number<>'000'";//SQL语句字符串(过滤是临时数据记录)
SqlCommand myCommand_Type_One = new SqlCommand(MySql_Type_One,myConnection);//建立新指令
SqlDataAdapter myAdapter_Type_One = new SqlDataAdapter();//建立数据读者
myAdapter_Type_One.SelectCommand = myCommand_Type_One;
DataSet Type_OneDS = new DataSet();//建立数据集
myAdapter_Type_One.Fill(Type_OneDS);//打开数据集
myConnection.Close();
Type_One_Text.Items.Clear();
Type_One_Text.DataSource=Type_OneDS;
Type_One_Text.DataTextField="Type_One_Name";
Type_One_Text.DataValueField="Type_One_Number";
Type_One_Text.DataBind(); if(Type_One_Text.Items.Count>0)
{
myConnection.Open();//打开连接
String MySql_Type_Two = "select * from Type_Two where Type_One_Number='"+Type_One_Text.Items[0].Value+"'";//SQL语句字符串
SqlCommand myCommand_Type_Two = new SqlCommand(MySql_Type_Two,myConnection);//建立新指令
SqlDataAdapter myAdapter_Type_Two = new SqlDataAdapter();//建立数据读者
myAdapter_Type_Two.SelectCommand = myCommand_Type_Two;
DataSet Type_TwoDS = new DataSet();//建立数据集
myAdapter_Type_Two.Fill(Type_TwoDS);//打开数据集
myConnection.Close();
Type_Two_Text.Items.Clear();
Type_Two_Text.DataSource=Type_TwoDS;
Type_Two_Text.DataTextField="Type_Two_Name";
Type_Two_Text.DataValueField="Type_Two_Number";
Type_Two_Text.DataBind(); if(Type_Two_Text.Items.Count>0)
{
myConnection.Open();//打开连接
String MySql_Type_Three = "select * from Type_Three where Type_Two_Number='"+Type_Two_Text.Items[0].Value+"'";//SQL语句字符串
SqlCommand myCommand_Type_Three = new SqlCommand(MySql_Type_Three,myConnection);//建立新指令
SqlDataAdapter myAdapter_Type_Three = new SqlDataAdapter();//建立数据读者
myAdapter_Type_Three.SelectCommand = myCommand_Type_Three;
DataSet Type_ThreeDS = new DataSet();//建立数据集
myAdapter_Type_Three.Fill(Type_ThreeDS);//打开数据集
myConnection.Close();
Type_Three_Text.Items.Clear();
Type_Three_Text.DataSource=Type_ThreeDS;
Type_Three_Text.DataTextField="Type_Three_Name";
Type_Three_Text.DataValueField="Type_Three_Number";
Type_Three_Text.DataBind();
}
}
}
#endregion
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.Web.Services;
using System.Data.SqlClient;namespace office_web
{
/// <summary>
/// product_Detail_WebForm 的摘要说明。
/// </summary>
public class product_Detail_WebForm : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button add_btn;
//定义WEB引用
protected myservice.myService WebReferences = null;
protected System.Web.UI.WebControls.DataGrid ProductDG;
protected System.Web.UI.WebControls.CheckBox chkExport;
protected System.Web.UI.WebControls.DropDownList Type_One_Text;
protected System.Web.UI.WebControls.DropDownList Type_Two_Text;
protected System.Web.UI.WebControls.DropDownList Type_Three_Text;
protected System.Web.UI.WebControls.Button Button1;
//定义数据库连接
protected SqlConnection myConnection;
//定义项目ID
protected int Project_id;
//定义配套表ID
protected int kit_id;
public string MySql;
public product_Detail_WebForm()
{
try
{
WebReferences = new myservice.myService();
}
catch { }
if (WebReferences == null)
{
// this.Response.Redirect("error.aspx?id=UnableToConnectRegisterService");
}
}
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
//得到项目ID
Project_id = int.Parse(this.Request["Project_id"].ToString());
//得到配套表ID
kit_id = int.Parse(this.Request["kit_id"].ToString());
if(!this.IsPostBack)
{
Type_One();
MySql ="select Type_Three.Type_Three_Name,Product.Product_Number,Type_Two.Type_Two_Name,Product.Product_Model_number,Product.Product_gg,Product.Product_Price,Product.Product_bit from Product,Type_Two,Type_Three where Product.Type_Three_Number=Type_Three.Type_Three_Number and Product.Type_Two_Number=Type_Two.Type_Two_Number";//SQL语句字符串
ProductDG.DataSource = product();
ProductDG.DataBind();
}
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Type_One_Text.SelectedIndexChanged += new System.EventHandler(this.Type_One_Text_SelectedIndexChanged);
this.Type_Two_Text.SelectedIndexChanged += new System.EventHandler(this.Type_Two_Text_SelectedIndexChanged);
this.Type_Three_Text.SelectedIndexChanged += new System.EventHandler(this.Type_Three_Text_SelectedIndexChanged);
this.add_btn.Click += new System.EventHandler(this.add_btn_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion #region 数据集
private DataSet product()
{
//连接数据库字符串
string ConnectionString = "Data Source="+WebReferences.strDS1()+"; Initial Catalog="+WebReferences.strDB1()+"; UID="+WebReferences.strUser1()+"; PWD="+WebReferences.strPwd1();
myConnection = new SqlConnection(ConnectionString);//建立连接
myConnection.Open();//打开连接
SqlCommand myCommand = new SqlCommand(MySql,myConnection);
SqlDataAdapter myAdapter = new SqlDataAdapter();
myAdapter.SelectCommand = myCommand;
DataSet DS = new DataSet();
myAdapter.Fill(DS);
myConnection.Close();
return DS;
}
#endregion #region 分页
public void ProductDG_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
{
//此处为分页用
ProductDG.CurrentPageIndex = e.NewPageIndex;
ProductDG.DataSource = product();
ProductDG.DataBind();
}
#endregion #region 绑定Type_One_Text数据
private void Type_One()
{
string ConnectionString = "Data Source="+WebReferences.strDS1()+"; Initial Catalog="+WebReferences.strDB1()+"; UID="+WebReferences.strUser1()+"; PWD="+WebReferences.strPwd1();
myConnection = new SqlConnection(ConnectionString);//建立连接
myConnection.Open();//打开连接
String MySql_Type_One = "select * from Type_One where Type_One_Number<>'000'";//SQL语句字符串(过滤是临时数据记录)
SqlCommand myCommand_Type_One = new SqlCommand(MySql_Type_One,myConnection);//建立新指令
SqlDataAdapter myAdapter_Type_One = new SqlDataAdapter();//建立数据读者
myAdapter_Type_One.SelectCommand = myCommand_Type_One;
DataSet Type_OneDS = new DataSet();//建立数据集
myAdapter_Type_One.Fill(Type_OneDS);//打开数据集
myConnection.Close();
Type_One_Text.Items.Clear();
Type_One_Text.DataSource=Type_OneDS;
Type_One_Text.DataTextField="Type_One_Name";
Type_One_Text.DataValueField="Type_One_Number";
Type_One_Text.DataBind(); if(Type_One_Text.Items.Count>0)
{
myConnection.Open();//打开连接
String MySql_Type_Two = "select * from Type_Two where Type_One_Number='"+Type_One_Text.Items[0].Value+"'";//SQL语句字符串
SqlCommand myCommand_Type_Two = new SqlCommand(MySql_Type_Two,myConnection);//建立新指令
SqlDataAdapter myAdapter_Type_Two = new SqlDataAdapter();//建立数据读者
myAdapter_Type_Two.SelectCommand = myCommand_Type_Two;
DataSet Type_TwoDS = new DataSet();//建立数据集
myAdapter_Type_Two.Fill(Type_TwoDS);//打开数据集
myConnection.Close();
Type_Two_Text.Items.Clear();
Type_Two_Text.DataSource=Type_TwoDS;
Type_Two_Text.DataTextField="Type_Two_Name";
Type_Two_Text.DataValueField="Type_Two_Number";
Type_Two_Text.DataBind(); if(Type_Two_Text.Items.Count>0)
{
myConnection.Open();//打开连接
String MySql_Type_Three = "select * from Type_Three where Type_Two_Number='"+Type_Two_Text.Items[0].Value+"'";//SQL语句字符串
SqlCommand myCommand_Type_Three = new SqlCommand(MySql_Type_Three,myConnection);//建立新指令
SqlDataAdapter myAdapter_Type_Three = new SqlDataAdapter();//建立数据读者
myAdapter_Type_Three.SelectCommand = myCommand_Type_Three;
DataSet Type_ThreeDS = new DataSet();//建立数据集
myAdapter_Type_Three.Fill(Type_ThreeDS);//打开数据集
myConnection.Close();
Type_Three_Text.Items.Clear();
Type_Three_Text.DataSource=Type_ThreeDS;
Type_Three_Text.DataTextField="Type_Three_Name";
Type_Three_Text.DataValueField="Type_Three_Number";
Type_Three_Text.DataBind();
}
}
}
#endregion
private void Type_Two()
{
string ConnectionString = "Data Source="+WebReferences.strDS1()+"; Initial Catalog="+WebReferences.strDB1()+"; UID="+WebReferences.strUser1()+"; PWD="+WebReferences.strPwd1();
myConnection = new SqlConnection(ConnectionString);//建立连接
myConnection.Open();//打开连接
String MySql_Type_Two = "select * from Type_Two where Type_One_Number='"+Type_One_Text.SelectedValue+"'";//SQL语句字符串
SqlCommand myCommand_Type_Two = new SqlCommand(MySql_Type_Two,myConnection);//建立新指令
SqlDataAdapter myAdapter_Type_Two = new SqlDataAdapter();//建立数据读者
myAdapter_Type_Two.SelectCommand = myCommand_Type_Two;
DataSet Type_TwoDS = new DataSet();//建立数据集
myAdapter_Type_Two.Fill(Type_TwoDS);//打开数据集
myConnection.Close();
Type_Two_Text.Items.Clear();
Type_Two_Text.DataSource=Type_TwoDS;
Type_Two_Text.DataTextField="Type_Two_Name";
Type_Two_Text.DataValueField="Type_Two_Number";
Type_Two_Text.DataBind(); if(Type_TwoDS.Tables[0].Rows.Count !=0)//如果Type_Two_Text下拉框有值
{
myConnection.Open();//打开连接
String MySql_Type_Three = "select * from Type_Three where Type_Two_Number='"+Type_Two_Text.SelectedItem.Value+"'";//SQL语句字符串
SqlCommand myCommand_Type_Three = new SqlCommand(MySql_Type_Three,myConnection);//建立新指令
SqlDataAdapter myAdapter_Type_Three = new SqlDataAdapter();//建立数据读者
myAdapter_Type_Three.SelectCommand = myCommand_Type_Three;
DataSet Type_ThreeDS = new DataSet();//建立数据集
myAdapter_Type_Three.Fill(Type_ThreeDS);//打开数据集
myConnection.Close();
Type_Three_Text.Items.Clear();
Type_Three_Text.DataSource=Type_ThreeDS;
Type_Three_Text.DataTextField="Type_Three_Name";
Type_Three_Text.DataValueField="Type_Three_Number";
Type_Three_Text.DataBind();
}
else
{
Type_Three_Text.Items.Clear();
}
}
#endregion #region 绑定Type_Three_Text数据
private void Type_Three()
{
string ConnectionString = "Data Source="+WebReferences.strDS1()+"; Initial Catalog="+WebReferences.strDB1()+"; UID="+WebReferences.strUser1()+"; PWD="+WebReferences.strPwd1();
myConnection = new SqlConnection(ConnectionString);//建立连接
myConnection.Open();//打开连接
String MySql_Type_Three = "select * from Type_Three where Type_Two_Number='"+Type_Two_Text.SelectedValue+"'";//SQL语句字符串
SqlCommand myCommand_Type_Three = new SqlCommand(MySql_Type_Three,myConnection);//建立新指令
SqlDataAdapter myAdapter_Type_Three = new SqlDataAdapter();//建立数据读者
myAdapter_Type_Three.SelectCommand = myCommand_Type_Three;
DataSet Type_ThreeDS = new DataSet();//建立数据集
myAdapter_Type_Three.Fill(Type_ThreeDS);//打开数据集
myConnection.Close();
Type_Three_Text.Items.Clear();
Type_Three_Text.DataSource=Type_ThreeDS;
Type_Three_Text.DataTextField="Type_Three_Name";
Type_Three_Text.DataValueField="Type_Three_Number";
Type_Three_Text.DataBind();
}
#endregion private void Type_One_Text_SelectedIndexChanged(object sender, System.EventArgs e)
{
MySql ="select Type_Three.Type_Three_Name,Product.Product_Number,Type_Two.Type_Two_Name,Product.Product_Model_number,Product.Product_gg,Product.Product_Price,Product.Product_bit from Product,Type_Two,Type_Three where Product.Type_Three_Number=Type_Three.Type_Three_Number and Product.Type_Two_Number=Type_Two.Type_Two_Number and Product.Type_Two_Number like '%"+Type_One_Text.SelectedValue+"%'";//SQL语句字符串
ProductDG.DataSource = product();
ProductDG.DataBind();
Type_Two();
} private void Type_Two_Text_SelectedIndexChanged(object sender, System.EventArgs e)
{
MySql ="select Type_Three.Type_Three_Name,Product.Product_Number,Type_Two.Type_Two_Name,Product.Product_Model_number,Product.Product_gg,Product.Product_Price,Product.Product_bit from Product,Type_Two,Type_Three where Product.Type_Three_Number=Type_Three.Type_Three_Number and Product.Type_Two_Number=Type_Two.Type_Two_Number and Product.Type_Two_Number like '"+Type_Two_Text.SelectedValue+"'";//SQL语句字符串
ProductDG.DataSource = product();
ProductDG.DataBind();
Type_Three();
} private void Type_Three_Text_SelectedIndexChanged(object sender, System.EventArgs e)
{
MySql ="select Type_Three.Type_Three_Name,Product.Product_Number,Type_Two.Type_Two_Name,Product.Product_Model_number,Product.Product_gg,Product.Product_Price,Product.Product_bit from Product,Type_Two,Type_Three where Product.Type_Three_Number=Type_Three.Type_Three_Number and Product.Type_Two_Number=Type_Two.Type_Two_Number and Product.Type_Three_Number like '"+Type_Three_Text.SelectedValue+"'";//SQL语句字符串
ProductDG.DataSource = product();
ProductDG.DataBind();
}
}
}
代码帖上来后自动换行了的。原来的不是这样的啊。
是遇到了这个问题吗?
是的。就是碰到了你所说的问题。已经弄了2天了,就是做不出来,快要想疯了。
怎么弄?
非常感谢!!!
特别感谢weijen()!!
问题已经解决。马上结帖!!