小问题急需解决,在线等待!!

时间:2021-06-06 19:04:33
小弟正在编一个网上订单的程序!
 我有这样一个想法:就是说所要采购的产品中有梨、苹果等,如果用户选择梨那么在选择品种的时候就显示雪花梨、水晶梨等,如果在所要采购的产品中选择苹果,那么在选择品种的时候就显示红富士、普通苹果等。
 哪位朋友可以帮助小弟完成此项工作啊,先谢了!解决后就给分!

6 个解决方案

#1


这个用两个表就可以解决了,一个放品种,一个放相应的品名!
用一个类型号为连接!

#2


我是用的两个文本框,产品后面一个文本框;品种后面一个文本框。
如果在产品后面那个文本框中选择梨,品种后面那个文本框就是显示雪花梨、水晶梨;如果在产品后面那个文本框中选择苹果,品种后面那个文本框就显示红富士、普通苹果等。
   哪位朋友快帮忙啊!

#3


自己写呀,很简单的,用数据库呀!新建两个表,如上。。。。。

#4


1--你也可以这样设计表格,一张表(两个字段,一个是名称--雪花梨、水晶梨,一个是类别--苹果,梨)
2--第一次显示类别时使用“select distinct 类别 from fruits”
3--选择以后使用“select 名称 from fruits where 类别='..'”
4--邦定显示

#5


同意wjh,类别使用下拉列表控件,具体明晰可以用datagrid,只需要把下拉表的autopostback设为true,然后再selectindexchanged事件中改变datagrid的数据源就可以了

#6


给你一段完整的代码吧:
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;

namespace test1
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.DropDownList DropDownList2;

private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if( IsPostBack == false)
{
Hashtable tabValues = new Hashtable(2);
tabValues.Add("苹果","苹果");
tabValues.Add("梨","梨");
DropDownList1.DataSource = tabValues;
DropDownList1.DataTextField = "Key";
DropDownList1.DataValueField = "Value";
DropDownList1.DataBind();
}
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{    
this.DropDownList1.SelectedIndexChanged += new System.EventHandler(this.DropDownList1_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{

switch(DropDownList1.SelectedItem.Value)
{
case "苹果":
Hashtable tabValues2 = new Hashtable(2);
tabValues2.Add("红富士","红富士");
tabValues2.Add("普通苹果","普通苹果");
DropDownList2.DataSource = tabValues2;
DropDownList2.DataTextField = "Key";
DropDownList2.DataValueField = "Value";
DropDownList2.DataBind();
break;
case "梨":
Hashtable tabValues3 = new Hashtable(2);
tabValues3.Add("雪花梨","雪花梨");
tabValues3.Add("水晶梨","水晶梨");
DropDownList2.DataSource = tabValues3;
DropDownList2.DataTextField = "Key";
DropDownList2.DataValueField = "Value";
DropDownList2.DataBind();
break;
}
}
}
}

HTML代码自己写,记得要把DropDownList的AutoPostBack 设为 true

#1


这个用两个表就可以解决了,一个放品种,一个放相应的品名!
用一个类型号为连接!

#2


我是用的两个文本框,产品后面一个文本框;品种后面一个文本框。
如果在产品后面那个文本框中选择梨,品种后面那个文本框就是显示雪花梨、水晶梨;如果在产品后面那个文本框中选择苹果,品种后面那个文本框就显示红富士、普通苹果等。
   哪位朋友快帮忙啊!

#3


自己写呀,很简单的,用数据库呀!新建两个表,如上。。。。。

#4


1--你也可以这样设计表格,一张表(两个字段,一个是名称--雪花梨、水晶梨,一个是类别--苹果,梨)
2--第一次显示类别时使用“select distinct 类别 from fruits”
3--选择以后使用“select 名称 from fruits where 类别='..'”
4--邦定显示

#5


同意wjh,类别使用下拉列表控件,具体明晰可以用datagrid,只需要把下拉表的autopostback设为true,然后再selectindexchanged事件中改变datagrid的数据源就可以了

#6


给你一段完整的代码吧:
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;

namespace test1
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.DropDownList DropDownList2;

private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if( IsPostBack == false)
{
Hashtable tabValues = new Hashtable(2);
tabValues.Add("苹果","苹果");
tabValues.Add("梨","梨");
DropDownList1.DataSource = tabValues;
DropDownList1.DataTextField = "Key";
DropDownList1.DataValueField = "Value";
DropDownList1.DataBind();
}
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{    
this.DropDownList1.SelectedIndexChanged += new System.EventHandler(this.DropDownList1_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{

switch(DropDownList1.SelectedItem.Value)
{
case "苹果":
Hashtable tabValues2 = new Hashtable(2);
tabValues2.Add("红富士","红富士");
tabValues2.Add("普通苹果","普通苹果");
DropDownList2.DataSource = tabValues2;
DropDownList2.DataTextField = "Key";
DropDownList2.DataValueField = "Value";
DropDownList2.DataBind();
break;
case "梨":
Hashtable tabValues3 = new Hashtable(2);
tabValues3.Add("雪花梨","雪花梨");
tabValues3.Add("水晶梨","水晶梨");
DropDownList2.DataSource = tabValues3;
DropDownList2.DataTextField = "Key";
DropDownList2.DataValueField = "Value";
DropDownList2.DataBind();
break;
}
}
}
}

HTML代码自己写,记得要把DropDownList的AutoPostBack 设为 true