2011-07-15 26 views
0

我正在使用中继器控件向用户显示在线问题纸张。我向用户展示了50个问题。我给每个问题4个复选框来选择答案。现在我的疑问是如何获得用户检查的所有50个选项,并将这些答案与我的XML中的正确答案标记进行比较。我正在使用XML文件,而不是数据库。如何从中继器控制中获取值

任何人都可以请帮助我如何实现此功能?

+0

你有什么尝试?你应该张贴一些代码来显示你到目前为止的内容。 –

回答

0

你必须遍历Repeater控制,如...

if (Repeater1.Items.Count > 0) 
{ 
    for (int count = 0; count < Repeater1.Items.Count; count++) 
    { 
     CheckBox chk = (CheckBox)Repeater1.Items[count].FindControl("CheckBox1"); 
     if (chk.Checked) 
     { 

     } 
    } 
} 
0

要访问Repeater商品,则应该使用:

repeaterId.Items 

要访问所有选中的一个中继器的控件(这是绝对RadioButton控件,你应该有每个问题一个选项),你可以使用:

foreach (ListViewDataItem item in repeaterId.Items) 
{ 
    // Finding RadioButton controls by Id 
    RadioButton firstOption = ((RadioButton)item.FindControl("firstOption")); 
    RadioButton secondOption = ((RadioButton)item.FindControl("secondOption")); 
    RadioButton thirdOption = ((RadioButton)item.FindControl("thirdOption")); 
    RadioButton fourthOption = ((RadioButton)item.FindControl("fourthOption")); 
    // Here you have four RadioButtones and you should only see which one of them is clicked. Then compare its value to correct value in your XML file. 
} 
+0

ListViewDataItem只存在于.NET 3.5以上。 Repeater.Items中Item的正确类型为RepeaterItem。 – SwissCoder

+0

另外,最好不要将控件明确地强制转换为RadioButton,而是使用下面的代码:item.FindControl(“FirstOption”)作为RadioButton; – SwissCoder