【发布时间】:2017-01-17 09:47:17
【问题描述】:
private void exam_Load(object sender, EventArgs e)
{
GetCount();
MySqlConnection con = new MySqlConnection("server = localhost; user id = root; password =; database = dbtest1;");
MySqlCommand cmd = new MySqlCommand("SELECT question, question_no, choice1, choice2, choice3, choice4 from quiz_tions where quiz_id = '" + lid + "' ORDER BY RAND() LIMIT " + count + ";", con);
MySqlDataAdapter sda = new MySqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
label5.DataBindings.Add("Text", dt, "question");
label6.DataBindings.Add("Text", dt, "question_no");
rb1.DataBindings.Add("Text", dt, "choice1");
rb2.DataBindings.Add("Text", dt, "choice2");
rb3.DataBindings.Add("Text", dt, "choice3");
rb4.DataBindings.Add("Text", dt, "choice4");
dataRepeater1.DataSource = dt;
LoadData();
label1.Text = qtitle;
label3.Text = qtype;
}
我的表单上有一个DataRepeater 控件,该控件是使用上面的代码填充的。每次执行这段代码。 . .
private void button3_Click(object sender, EventArgs e)
{
foreach (DataRepeaterItem c in dataRepeater1.Controls)
{
ss += ((Label)c.Controls["label5"]).Text + "\n";
}
MessageBox.Show(ss);
ss = "";
}
当我在单击按钮之前单击不同的行(有时是 3 行,有时是 4 行)时,它会给我带来不同的结果,而且这并不总是正确的,因为当我执行该操作时,我的 DataRepeater 控件上有 5 行。为什么会这样?遍历DataRepeater 的行的正确方法是什么?
附:另一个与我的帖子无关的问题(可能)是每当我在DataRepeater 上向下/向上滚动时,有时它会自动检查列表中的随机RadioButton。这个控件有什么问题?
【问题讨论】:
-
还是一样:(
-
您确定
label5.Text在某些转发器项目中不为空吗? -
是的,它们不是空的。
-
ss是TextBox类型?如果是,请尝试...+ "\r\n"而不是...+"\n" -
ss是Global string,您在下面发布的答案仍然无效。我认为问题出在DataRepeater。
标签: c# winforms datarepeater