【发布时间】:2014-07-07 20:09:24
【问题描述】:
我正在为 Sharepoint 开发一个随机测验生成器,但在检查所选答案是否与正确答案匹配时,我遇到了一个小问题。
我有一个声明为全局的单选按钮列表。
public static RadioButtonList[] RadioButtonList = new RadioButtonList[5]; //5 elements are enough, as i'll stick to a 5-question quiz for now.
然后,在填充下拉列表时,我正在创建一个新对象并将项目(答案)添加到列表中。
for (var i=0; ... )
...
RadioButtonList[i] = new RadioButtonList();
RadioButtonList[i].Items.Add(SPListItemCollection[index]["Column"].ToString());
...
到目前为止一切正常。以上都发生在生成代码的按钮的点击事件中。
我的问题出现在以下事件中,针对“比较”按钮。 我正在尝试将选定的单选按钮值与存储在标签中的另一个值进行比较,该值代表正确的答案。问题是,以下条件不起作用:
for (var index ... )
....
if (RadioButtonList[index].SelectedValue.Equals(label_Response[index].Text))
...
“RadioButtonList[index].SelectedValue”始终为空,调试时出现 NullReferenceException。
如果有人能帮我解决这个问题,或者知道更好的解决方案,我将非常感激。
提前致谢, 卡琳。
【问题讨论】:
标签: c# sharepoint radiobuttonlist