I need to check wheather the radionbutton is checked Or NOT then need to have its value to a variable .
How can i loop through the radioButtonList in repeater to check that user choose True or false on button click and button is placed outside the gridview and repeater.
I tried this: protected void btnsave_Click(object sender, EventArgs e) { if (!Page.IsValid) return; int tcounter = 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();
}
}
}
}
but shows error: Unable to cast object of type 'System.Web.UI.WebControls.Repeater' to type 'System.Web.UI.WebControls.GridView'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Unable to cast object of type 'System.Web.UI.WebControls.Repeater' to type 'System.Web.UI.WebControls.GridView'.
Source Error:
Line 89: for (int i = 0; i < gridMainSurveyQuestion.Rows.Count; i++) Line 90: { Line 91: GridView grid = (GridView)gridMainSurveyQuestion.Rows[i].FindControl("RptQuestions"); Line 92: Line 93: Repeater repea = (Repeater)grid.Rows[i].FindControl("RptQuestions");
Source File: C:\Users\madiha.rahman\Desktop\PICG_SurveyModule\PICG_SurveyModule\Survey.aspx.cs Line: 91
can you correct it