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

解决方案 »

  1.   

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

  2.   

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