ラジオボタンがチェックされているかどうかを確認する必要があります。その値を変数に設定する必要があります。
ボタンのクリック時にユーザーがTrueまたはFalseを選択し、ボタンがグリッドビューとリピーターの外側に配置されていることを確認するために、リピーターでradioButtonListをループするにはどうすればよいですか。
私はこれを試しました: protected void btnsave_Click(object sender, EventArgs e) { if (!Page.IsValid) return; int カウンター = 0; int fcounter = 0;
for (int i = 0; i < gridMainSurveyQuestion.Rows.Count; i++)
{
GridView grid = (GridView)gridMainSurveyQuestion.Rows[i].FindControl("RptQuestions");
Repeater repea = (Repeater)grid.Rows[i].FindControl("RptQuestions");
for (int j = 0; j < repea.Items.Count; j++)
{
RepeaterItem currentitem = repea.Items[j];
RadioButtonList rlist = (RadioButtonList)currentitem.FindControl("rblanswer");
if (rlist.SelectedItem.Value == "0")
{
fcounter++;
lblfalse.Text = fcounter.ToString();
}
if (rlist.SelectedItem.Value == "1")
{
tcounter++;
lbltrue.Text = tcounter.ToString();
}
}
}
}
しかし、エラーが表示されます: タイプ 'System.Web.UI.WebControls.Repeater' のオブジェクトをタイプ 'System.Web.UI.WebControls.GridView' にキャストできません。
説明: 現在の Web 要求の実行中に未処理の例外が発生しました。エラーの詳細とコード内のどこでエラーが発生したかについては、スタック トレースを確認してください。
例外の詳細: System.InvalidCastException: タイプ 'System.Web.UI.WebControls.Repeater' のオブジェクトをタイプ 'System.Web.UI.WebControls.GridView' にキャストできません。
ソース エラー:
89 行目: for (int i = 0; i < gridMainSurveyQuestion.Rows.Count; i++) 90 行目: { 91 行目: GridView grid = (GridView)gridMainSurveyQuestion.Rows[i].FindControl("RptQuestions"); 92 行目: 93 行目: リピーター repea = (Repeater)grid.Rows[i].FindControl("RptQuestions");
ソース ファイル: C:\Users\madiha.rahman\Desktop\PICG_SurveyModule\PICG_SurveyModule\Survey.aspx.cs 行: 91
修正できますか