how to display the error message for not selecting the question?

Posted by Tejamanimala under ASP.NET on 5/14/2013 | Points: 10 | Views : 791 | Status : [Member] | Replies : 3
hi,i have online exam paper,in that i have 30 questions with multiple options,each question have 4 multiple choice answers.My doubt is,if i didn't select any of one of the question,and i am going to the next question,then immediately,i want to display the error message as please select the 3rd question or 4th question,near question only,how it is possible to display the message?(i have 30 questions in a page)
my code is...........
if ((RadioButtonList1.SelectedValue) == dsCurrent.Tables[0].Rows[0]["CorrectOption"].ToString())
{
if (RadioButtonList1.SelectedValue == "")
{
sb.Append("1");
sb.Append(",");
}
i++;
SqlCommand cmd1 = new SqlCommand("insert into StudentExamFullResult (UserID,Question,SelectedOption,CorrectOption) values('"+Label32.Text+"','" + dsCurrent.Tables[0].Rows[0]["Question"].ToString() + "','" + RadioButtonList1.SelectedValue + "','" + dsCurrent.Tables[0].Rows[0]["CorrectOption"].ToString() + "')", con);
cmd1.ExecuteNonQuery();
}

else
{
f (RadioButtonList1.SelectedValue == "")
{
sb.Append("1");
sb.Append(",");
}
SqlCommand cmd1 = new SqlCommand("insert into StudentExamFullResult (UserID,Question,SelectedOption,CorrectOption) values('" +Label32.Text + "','" + dsCurrent.Tables[0].Rows[0]["Question"].ToString() + "','" + RadioButtonList1.SelectedValue + "','" + dsCurrent.Tables[0].Rows[0]["CorrectOption"].ToString() + "')", con);
cmd1.ExecuteNonQuery();
}

if ((RadioButtonList2.SelectedValue) == dsCurrent.Tables[0].Rows[1]["CorrectOption"].ToString())
{
if (RadioButtonList2.SelectedValue == "")
{
sb.Append("2");
sb.Append(",");
}
i++;
SqlCommand cmd2 = new SqlCommand("insert into StudentExamFullResult (UserID,Question,SelectedOption,CorrectOption) values('" + Label32.Text + "','" + dsCurrent.Tables[0].Rows[1]["Question"].ToString() + "','" + RadioButtonList2.SelectedValue + "','" + dsCurrent.Tables[0].Rows[1]["CorrectOption"].ToString() + "')", con);
cmd2.ExecuteNonQuery();
}
else
{
if (RadioButtonList2.SelectedValue == "")
{
sb.Append("2");
sb.Append(",");
}
SqlCommand cmd2 = new SqlCommand("insert into StudentExamFullResult (UserID,Question,SelectedOption,CorrectOption) values('" + Label32.Text + "','" + dsCurrent.Tables[0].Rows[1]["Question"].ToString() + "','" + RadioButtonList2.SelectedValue + "','" + dsCurrent.Tables[0].Rows[1]["CorrectOption"].ToString() + "')", con);
cmd2.ExecuteNonQuery();
}

manimala


Responses

Posted by: Tejamanimala on: 5/14/2013 [Member] Starter | Points: 25

Up
0
Down
and for not selecting all questions i wrote like
string bulider = sb.ToString();
if (bulider != "")
{
ScriptManager.RegisterStartupScript(this, GetType(), "alert", "alert('Please select " + bulider + " question(s)')", true);
}
else
{
ScriptManager.RegisterStartupScript(this, GetType(), "alert", "alert('Congratulations " + Label32.Text + " answers successfully submited ')", true);
string x = System.Web.HttpContext.Current.Session["Domain"].ToString();
SqlCommand cmd1 = new SqlCommand("insert into Resultsforstudents (UserID,UserName,Domain,Date,Marks) values('" + Label32.Text + "','" + Label33.Text + "','" + x + "','" + DateTime.Now.ToString() + "','" + i + "')", con);
cmd1.ExecuteNonQuery();
Response.Redirect("LogOut.aspx");
}

manimala

Tejamanimala, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Annaharris on: 5/14/2013 [Member] Starter | Points: 25

Up
0
Down
Thanks for sharing the code, but what is the issue that you are facing? Aren't you able to display the message after every question?

Tejamanimala, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Tejamanimala on: 5/15/2013 [Member] Starter | Points: 25

Up
0
Down
yes Annaharris,i am not able to display the message after every question,it is displaying the message after clicking on submit button

manimala

Tejamanimala, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response