c#项目中动态创建radiobutton,为什么不会更新?
privatevoidbrowse(){stringsql1="select*fromanswerwherequestion_id='"+id[N]+"'";DataSe...
private void browse() {
string sql1 = "select * from answer where question_id='" +id[N]+ "'";
DataSet ds1 = SqlHelper.ExecuteDataset(SqlHelper.connectionString, CommandType.Text, sql1);
string[] answer = new string[ds1.Tables[0].Rows.Count];
for (int j = a; j < ds1.Tables[0].Rows.Count; j++) {
DataRow dr3 = ds1.Tables[0].Rows[j];
answer[j] = Convert.ToString(dr3[1]);
}
RadioButton[] radioButtons= new RadioButton[answer.Length];
for (int i = 0; i < answer.Length; ++i) {
//MessageBox.Show(answer[i]);
radioButtons[i] = new RadioButton();
radioButtons[i].Text = answer[i];
radioButtons[i].Location = new System.Drawing.Point(
10, 20 + i * 30);
groupBox1. Controls.Add(radioButtons[i]);
}
private void btnnext_Click(object sender, EventArgs e)
{
N = N + 1;
if (N == Total)
{
MessageBox.Show("已经是最后一题!");
}
else
{
browse();
}
}
}
点击btnnext时radiobutton内容不会更新,测试answer数组会更新,求解! 展开
string sql1 = "select * from answer where question_id='" +id[N]+ "'";
DataSet ds1 = SqlHelper.ExecuteDataset(SqlHelper.connectionString, CommandType.Text, sql1);
string[] answer = new string[ds1.Tables[0].Rows.Count];
for (int j = a; j < ds1.Tables[0].Rows.Count; j++) {
DataRow dr3 = ds1.Tables[0].Rows[j];
answer[j] = Convert.ToString(dr3[1]);
}
RadioButton[] radioButtons= new RadioButton[answer.Length];
for (int i = 0; i < answer.Length; ++i) {
//MessageBox.Show(answer[i]);
radioButtons[i] = new RadioButton();
radioButtons[i].Text = answer[i];
radioButtons[i].Location = new System.Drawing.Point(
10, 20 + i * 30);
groupBox1. Controls.Add(radioButtons[i]);
}
private void btnnext_Click(object sender, EventArgs e)
{
N = N + 1;
if (N == Total)
{
MessageBox.Show("已经是最后一题!");
}
else
{
browse();
}
}
}
点击btnnext时radiobutton内容不会更新,测试answer数组会更新,求解! 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询