我晕,不,那句,是循环加入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的值。 }} 就是以上语句
你是要通过两个循环生成输入分数的界面?content[i,j] = "<input type=text name=\"" + name + "\" id=\"" + name + "\" style=\"width:40px\">分"; 现在的错误在哪里?请说清楚
用datagrid模板列,item 设置为textbox。 应该可以。而且提交也方便
to: cyp503(谁怕?一蓑烟雨任平生) 循环生成分数输入框没错,我就是取得其值放入数组,不知道怎么放, 你最好再看一下我问的问题,我只是在取值一大堆的输入框中的值并对应学生放入数组有点问题。
>>>>还有,我说过不用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
唉,你是叫我用datagrid啊,不用不行吗?
you can use anything, but it is much easier if you use datagrid
建议一个学生一个学生的输入成绩,既清楚又不易出错。
我是想跟据ID来判断放到哪一维的。但是无法做到。ID我也做了标记了。
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);
}
}
}
还有,我说过不用DataGrid,课目是自选的。不用什么增加。
所以无法取得值。
我是这样子的,在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的值。
}}
但取值到数组,还是不行。有办法吗?
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())
{
}
才能实现循环
dr : DataRow dr = ds.Tables[0].Row[i] 并不是DataReader
我告诉你输入框已经生成了,但是要取值的时候,我就得在
Page.IsPostBack中取。
这句是取得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;
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的值。
}}
就是以上语句
现在的错误在哪里?请说清楚
应该可以。而且提交也方便
循环生成分数输入框没错,我就是取得其值放入数组,不知道怎么放,
你最好再看一下我问的问题,我只是在取值一大堆的输入框中的值并对应学生放入数组有点问题。
// 语文 数学 英语……
//甲
//乙
//丙则,乙同学的英语保存在myArray(2,3)*我的方法是所有同学所有科目都循环一次假设现在生成的输入界面是
英语
乙 [TextBox id="2_3"]
假设能取到值的话即
TextBox _txtBox=(TextBox)this.Page.FindControl(id);
if(_txtBox!=null)
{
//通过数组的SetValue()方法赋值
}
else
{
//没有取得值,即用户输入界面中不包括此项,例如乙同学的语文成绩
}