我不是数据绑定的。我是用的HtmlTable跟据课目的多少来加入文本输入框的。
输入框是动态的。我没有用DataGrid和DataList。是用的自写的一个HtmlTable列表类。

解决方案 »

  1.   

    这个方法很不可取,要是学生有几百个呢,把所有学生都罗列出来,那要多少textbox来伺候啊。
    建议一个学生一个学生的输入成绩,既清楚又不易出错。
      

  2.   

    你把你动态生成的文本框记录下来,比如用放到ARRAYlIST中
      

  3.   

    我知道,我就是想放到数组里的。但是怎么放,又怎么取?
    我是想跟据ID来判断放到哪一维的。但是无法做到。ID我也做了标记了。
      

  4.   

    这个问题有什么难的呢,你在DataGrid上面做一个按钮,点一下,datagrid增加一格.不过每次点ADD时数据的状态用Session来保存.其实是个很容易的操作,没有什么难度.
      

  5.   

    int _studentsCount=10;  //学生总数
    int _subjectCount=6;   //科目总数
    string[,] _scores=new string[_studentsCount,_subjectCount];//
    //从数据库读书信息,把所有学生和学科放进数组
    //表的形式为
    //   语文 数学 英语……
    //甲
    //乙
    //丙//保存每个考生每课成绩
    for(int i=0;i<_studentsCount;i++)
    {
    for(int j=0;j<_subjectCount;j++)
    {
                string _ctlID="input_"+i.ToString()+"_"+j.ToString();
    TextBox _txtBox = (TextBox)this.Page.FindControl(_ctlID);
    if(_txtBox!=null && _txtBox.Text!="")
    {
    _scores.SetValue(_txtBox.Text.Trim(),i,j);
              }
    }
    }
      

  6.   

    cyp503(谁怕?一蓑烟雨任平生) 您的方法好像有用。我试试。
    还有,我说过不用DataGrid,课目是自选的。不用什么增加。
      

  7.   

    不行,我无法得到ID:string _ctlID="input_"+i.ToString()+"_"+j.ToString();
    所以无法取得值。
    我是这样子的,在Page_OnLoad中
    //片断代码
    int dscount = ds.Tables[0].Rows.Count;
    StudentNum = dscount; string[,] content = new string[dscount,title.Length + 1]; for(int i = 0; i < dscount; i ++)
    {
    DataRow dr = ds.Tables[0].Rows[i];
    string stuID = dr["StudentID"].ToString();
    for(int j = 0; j <= title.Length; j ++)
    {
    int no = i + 1;
    if(j == 0)
    {
    content[i,j] = dr["Name"].ToString();
    }
    else if(j == title.Length)
    {
    content[i,j] = stuID;
    }
    else
    {
                                                                    //定义textbox的ID
    string name = "input" + "_" + stuID + "_" + SubjectValue[j-1] + "_" + no.ToString();
    content[i,j] = "<input type=text name=\"" + name + "\" id=\"" + name + "\" style=\"width:40px\">分";
    }
    }
    } string[][] button = new string[][]{new string[]{"btn_Submit","确定","","submit"}}; div_ListTable.Controls.Add(new ListTable().BinderTable(dscount,title,content,false,false,false,false,button,true,true));
    然后,再判断
    if(Page.IsPostBack)
    {
        //在此取值
       foreach(string item in Request.Form.AllKeys)
    {
    System.Text.RegularExpressions.Regex r = new Regex(@"^input_(\d+)_(\d+)_(\d+)$");
    if(r.IsMatch(item.ToString()))
                                                  {
                                                    //这里得到所有textbox的值。
                                                   }}
    但取值到数组,还是不行。有办法吗?
      

  8.   

    不大明白你这段是干什么的?是生成输入界面还是取得用户所填写的值?? int dscount = ds.Tables[0].Rows.Count;
    StudentNum = dscount; string[,] content = new string[dscount,title.Length + 1]; for(int i = 0; i < dscount; i ++)
    {
    DataRow dr = ds.Tables[0].Rows[i];
    string stuID = dr["StudentID"].ToString();
    for(int j = 0; j <= title.Length; j ++)
    {
    int no = i + 1;
    if(j == 0)
    {
    content[i,j] = dr["Name"].ToString();
    }
    else if(j == title.Length)
    {
    content[i,j] = stuID;
    }
    else
    {
    //定义textbox的ID
    string name = "input" + "_" + stuID + "_" + SubjectValue[j-1] + "_" + no.ToString();
    content[i,j] = "<input type=text name=\"" + name + "\" id=\"" + name + "\" style=\"width:40px\">分";
    }
    }
    }
    --------------
    string stuID = dr["StudentID"].ToString();dr是否为DataReader?如果是的话,逻辑是有问题的,因为只有
    while(dr.Read())
    {
    }
    才能实现循环
      

  9.   

    上一断代码是生成输入框,输入框生成后,我要取它的值并放到数组中。
    dr : DataRow dr = ds.Tables[0].Row[i] 并不是DataReader
    我告诉你输入框已经生成了,但是要取值的时候,我就得在
    Page.IsPostBack中取。
      

  10.   

    >>>content[i,j] = "<input type=text name=\"" + name + "\" id=\"" + name + "\" style=\"width:40px\">分";
    这句是取得TextBox的值吗?改成这样:string name = "input" + "_" + stuID + "_" + SubjectValue[j-1] + "_" + no.ToString();TextBox _txtBox=(TextBox)this.Page.FindControl(name);
    if(_txtBox!=null && _txtBox.Text!="")
        content[i,j]=_txtBox.Text;
      

  11.   

    我晕,不,那句,是循环加入textbox输入框.取值没取.TextBox _txtBox=(TextBox)this.Page.FindControl(name);
    if(_txtBox!=null && _txtBox.Text!="")
        content[i,j]=_txtBox.Text;
    我倒,又是这样,这样根本就不能在
    page.ispostback中取得。
    取值时在Page.IsPostBack中取得。
    if(Page.IsPostBack)
    {
        //在此取值
       foreach(string item in Request.Form.AllKeys)
    {
    System.Text.RegularExpressions.Regex r = new Regex(@"^input_(\d+)_(\d+)_(\d+)$");
    if(r.IsMatch(item.ToString()))
                                                  {
                                                    //这里得到所有textbox的值。
                                                   }}
    就是以上语句
      

  12.   

    你是要通过两个循环生成输入分数的界面?content[i,j] = "<input type=text name=\"" + name + "\" id=\"" + name + "\" style=\"width:40px\">分";
    现在的错误在哪里?请说清楚
      

  13.   

    用datagrid模板列,item 设置为textbox。
    应该可以。而且提交也方便
      

  14.   

    to: cyp503(谁怕?一蓑烟雨任平生) 
    循环生成分数输入框没错,我就是取得其值放入数组,不知道怎么放,
    你最好再看一下我问的问题,我只是在取值一大堆的输入框中的值并对应学生放入数组有点问题。
      

  15.   

    >>>>还有,我说过不用DataGrid,课目是自选的。不用什么增加doesn't the client care how you did it? I doubtuse DataGrid, your life will be much easier, since you can get values in a loop and update your database with a DataAdapter
      

  16.   

    唉,你是叫我用datagrid啊,不用不行吗?
      

  17.   

    you can use anything, but it is much easier if you use datagrid
      

  18.   

    看你的要求,用datagrid实现起来却是简单,不用写那么多的代码了
      

  19.   

    其实我已说得很明白一开始,把所有的学生和学科取出来构建一个二维数组,类似于//表的形式为
    //   语文 数学 英语……
    //甲
    //乙
    //丙则,乙同学的英语保存在myArray(2,3)*我的方法是所有同学所有科目都循环一次假设现在生成的输入界面是
        英语
    乙 [TextBox id="2_3"]
    假设能取到值的话即
    TextBox _txtBox=(TextBox)this.Page.FindControl(id);
    if(_txtBox!=null)
    {
        //通过数组的SetValue()方法赋值
    }
    else
    {
       //没有取得值,即用户输入界面中不包括此项,例如乙同学的语文成绩
    }