本帖最后由 wangxianshou 于 2009-08-09 02:01:34 编辑

解决方案 »

  1.   

            private string[][] DiaoCha = new string[][] { 
                new string[] { "Sex", "nan", "nv" }
                ,new string[] { "Age","10","20","30","40"}
            ,new string[]{"Price","pianyi","zhenghao","gui"}};如何遍历呢?
    先判断出有多少调查,然后每个调查有几个选项
      

  2.   


    foreach(string[] strs in DiaoCha)
    {
        for(int i = 0;i<strs.Length;i++)
        {
            if(i == 0)//等于名字
        }
    }
      

  3.   


    //定义调查类
    public class Survey
    {
       public List<Item> Items =new List<Item>;
    }//定义每个调查项目
    public class Item
    {
       public Control QuestionControl;
       public Control[] AnswerControls = new Control[]();
       public AnswerType AnswerType;
    }//每个调查项的回复方式枚举(作用后述)
    public enum AnswerType 
    {
       //反馈内容需输入文本
       Text,
       //复选
       CheckBox,
       //单选
       RadioButton,
       //下拉
       DropDown,
    }/*
    调查项目: 
    性别:男,女 
    年龄:10,20,30,40,50,60以上 
    口味:好吃,一般,不好吃 
    价格:便宜,适合,贵 
    购买原因:外观好看,货好,便宜
    */
    void Main(string [] arges)
    {
       //这里假设每一个控件的构造方法都是设置Text为传入的string.
       Survey s = new Survey();
       Item item = new Item();
       item.QuestionControl = new Label("性别"); 
       item.AnswerControls.Add(new RadioButton("男"));
       item.AnswerControls.Add(new RadioButton("女"));
       item.AnswerType = Answer.RadioButton;
       s.Items.Add(item);   item.QuestionControl = new Label("年龄"); 
       item.AnswerControls.Add(new RadioButton("10"));
       item.AnswerControls.Add(new RadioButton("20"));
       item.AnswerControls.Add(new RadioButton("30"));
       item.AnswerControls.Add(new RadioButton("40"));
       item.AnswerControls.Add(new RadioButton("50"));
       item.AnswerControls.Add(new RadioButton("60"));
       item.AnswerControls.Add(new RadioButton("60以上"));
       item.AnswerType = Answer.RadioButton;
       s.Items.Add(item);
       
       //其他的照加,这里主要演示多选的情况
       item.QuestionControl = new Label("购买原因"); 
       item.AnswerControls.Add(new CheckBox("外观好看"));
       item.AnswerControls.Add(new CheckBox("货好"));
       item.AnswerControls.Add(new CheckBox("便宜"));
       item.AnswerType = AnswerType.CheckBox;
       s.Items.Add(item);
       //显示.
       foreach (Item it in s.Items)
         {
             //显示选项文本控件
            //自己实现布局.本处未实现
            it.QuestionControl.Show();
            for (int i = 0;i<it.AnswerControls.Count;i++)
               {
                     //显视备选内容控件
                    //自己实现布局.本处未实现
                   it.AnswerControls[i].Show();
                }
         }
       
       //将调查结果读到Hashtable,也可以是DataTable
       Hashtable hash = new Hashtable();
       foreach (Item it in s.Items)
         {
            string answerStr = "";
            for (int i = 0;i<it.AnswerControls.Count;i++)
               {
                   if (it.AnswerType == AnswerType.RidioButton && ((RadioButton)it.AnswerControls[i]).Checkd)
                     {
                        answerStr = answerStr + AnswerControls[i].Text;
                        break;
                     }
                    else if (it.AnswerType == AnswerType.CheckBox && ((CheckBox)it.AnswerControls[i]).Checkd)
                     {
                        answerStr = answerStr + AnswerControls[i].Text;
                     }
                    //可以加入其他判断
                }
            hash.Add(it.QuestionControl.Text,answerStr );
         }
    }
      

  4.   

            private DataTable dtContent;
    private string[][] Content =null;
    --------------------------------------------------------------------
    dtContent=this.database.GetContentDetails();//从数据库中拿到数据
    DataView dv = dtContent.DefaultView;
    dv.Sort = "ContentID";
    ArrayList al = new ArrayList();
    foreach (DataRowView row in dv)//拿到所有的组
    {
    if (!al.Contains(row["ContentGroup"].ToString().Trim()))
    {
    al.Add(row["ContentGroup"].ToString().Trim());
    }
    }
    Content = new string[al.Count][];//交叉数组的初始化
    for (int i = 0; i < al.Count; i++)
    {
    dv.RowFilter = string.Format("ContentGroup='{0}'", al[i].ToString());
    Content[i] = new string[dv.Count+1];//交叉数组的初始化
    Content[i][0] = al[i].ToString();//放入一个组号 for (int j = 0; j < dv.Count; j++)
    {
    Content[i][j+1] = dv[j]//放入这个组的所有成员["ContentDetail"].ToString();
    }
    }