2011-07-15 4 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のコントロールです。質問ごとに1つのオプションが必要です)、次を使用できます。

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")as RadioButton; – SwissCoder

関連する問題