下面是生成Label和TextBox,但是不知道为什么就是获得不到TextBox里面的值!
public void show(string Topic,string TopicID,string Score)
{
this.Label3.Text=Topic;
this.Label2.Text=Score;
int ti=Convert.ToInt32(TopicID);
string sql,Answe_ID="",rbID="";
sql="select * from Subjective_Answer where TopicID='"+ti+"' and Score=-1 ";
try
{
conn.Open();
SqlCommand sqlcommand=new SqlCommand(sql,conn);
SqlDataReader reader=sqlcommand.ExecuteReader();
int num=1;
while(reader.Read())
{
Answe_ID+=reader["Answe_ID"].ToString()+"~";
Label lb=new Label();
TextBox tb=new TextBox();
lb.Height=10;
lb.Width=500;
tb.Width=50;
tb.ID=Convert.ToString(num);
lb.Text = Convert.ToString(num)+". "+reader["Answer"].ToString();
this.Panel1.Controls.Add(lb);
this.Panel1.Controls.Add(tb);
num++;
}
}
catch(Exception e)
{
}
conn.Close();
}
获得的方法,请各位高手指点一下.
string ans6="";
for(int i=1;i<=50;i++)
{
TextBox list=new TextBox();
list=(TextBox)Panel1.FindControl("tb"+i.ToString());
if(list!=null)
{
ans6+=list.Text+"~";
}
}
this.Label5.Text=ans6;
public void show(string Topic,string TopicID,string Score)
{
this.Label3.Text=Topic;
this.Label2.Text=Score;
int ti=Convert.ToInt32(TopicID);
string sql,Answe_ID="",rbID="";
sql="select * from Subjective_Answer where TopicID='"+ti+"' and Score=-1 ";
try
{
conn.Open();
SqlCommand sqlcommand=new SqlCommand(sql,conn);
SqlDataReader reader=sqlcommand.ExecuteReader();
int num=1;
while(reader.Read())
{
Answe_ID+=reader["Answe_ID"].ToString()+"~";
Label lb=new Label();
TextBox tb=new TextBox();
lb.Height=10;
lb.Width=500;
tb.Width=50;
tb.ID=Convert.ToString(num);
lb.Text = Convert.ToString(num)+". "+reader["Answer"].ToString();
this.Panel1.Controls.Add(lb);
this.Panel1.Controls.Add(tb);
num++;
}
}
catch(Exception e)
{
}
conn.Close();
}
获得的方法,请各位高手指点一下.
string ans6="";
for(int i=1;i<=50;i++)
{
TextBox list=new TextBox();
list=(TextBox)Panel1.FindControl("tb"+i.ToString());
if(list!=null)
{
ans6+=list.Text+"~";
}
}
this.Label5.Text=ans6;
Label和TextBox已经生成?
已经从数据库读取出来。.自己也在TextBox写了东西。2楼
tb.ID=Convert.ToString(num);//这里不是设置为数字吗?
NUM为INT的.
list=(TextBox)Panel1.FindControl("tb"+i.ToString());//为什么又加上tb??
那个tb是我原来写的时候加的。.去掉也一样。.
原来在生成的时候有tb.ID="tb"+Convert.ToString(num);3楼。
通过ID??那个ID?
4楼..
show在每次Page_Load时先调用,然后才可以得到textbox的值
一定要再Page_Load时先调用?用按钮不行吗?
list=(TextBox)Panel1.FindControl("tb"+i.ToString());
这一句获得不到...
但是我不知道要怎么改好。
改了好几次都是一样...