I am using alert from server side to display the not attempted question
HTML:
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.0.min.js">
</script>
<script type="text/javascript">
function RadioCheck(rb) {
$(rb).parent().css("border", "4px solid #CCCCCC");
//finding table inside dlQuestion
var radioButton = $(rb).parent().parent().parent().parent().find("input");
var row = rb.parentNode.parentNode;
for (var i = 0; i < radioButton.length; i++) {
if (radioButton[i].type == "radio") {
if (radioButton[i] != rb) {
radioButton[i].checked = false;
$(radioButton[i]).parent().css("border", "0px");
}
}
}
};
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DataList ID="DataList1" runat="server">
<ItemTemplate>
(<%#Container.ItemIndex+1 %>)
<asp:Label ID="Label1" runat="server" Text='<%# bind("QuestionDescription") %>' Font-Bold="True"></asp:Label><br />
<table id="QuestionAnswer" runat="server">
<tr>
<td>
<asp:RadioButton ID="RadioButton1" onclick="RadioCheck(this);" runat="server" GroupName="Questions"
Text='<%# bind("OptionOne") %>' />
</td>
</tr>
<tr>
<td>
<asp:RadioButton ID="RadioButton2" onclick="RadioCheck(this);" runat="server" GroupName="Questions"
Text='<%# bind("OptionTwo") %>' />
</td>
</tr>
<tr>
<td>
<asp:RadioButton ID="RadioButton3" onclick="RadioCheck(this);" runat="server" GroupName="Questions"
Text='<%# bind("OptionThree") %>' />
</td>
</tr>
<tr>
<td>
<asp:RadioButton ID="RadioButton4" onclick="RadioCheck(this);" runat="server" GroupName="Questions"
Text='<%# bind("OptionFour") %>' />
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="Submit" />
</div>
</form>
</body>
</html>
C#:
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.Populate();
}
}
private void Populate()
{
string constr = ConfigurationManager.ConnectionStrings["ConString2"].ConnectionString;
using (SqlConnection _cn = new SqlConnection(constr))
{
using (SqlCommand _cmd = new SqlCommand("SELECT * FROM QuestionTable", _cn))
{
using (SqlDataAdapter da = new SqlDataAdapter(_cmd))
{
DataSet ds = new DataSet();
da.Fill(ds);
this.DataList1.DataSource = ds;
this.DataList1.DataBind();
}
}
}
}
protected void Submit(object sender, EventArgs e)
{
string notAttemptedQuestion = string.Empty;
foreach (DataListItem item in DataList1.Items)
{
int index = item.ItemIndex + 1;
bool a = (item.FindControl("RadioButton1") as RadioButton).Checked;
bool b = (item.FindControl("RadioButton2") as RadioButton).Checked;
bool c = (item.FindControl("RadioButton3") as RadioButton).Checked;
bool d = (item.FindControl("RadioButton4") as RadioButton).Checked;
string answer = string.Empty;
if (!a && !b && !c && !d)
{
notAttemptedQuestion += index.ToString() + ", ";
}
}
string message = string.Format("Not Attempted Question: {0}.", notAttemptedQuestion.Remove(notAttemptedQuestion.LastIndexOf(',')));
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<script type = 'text/javascript'>");
sb.Append("window.onload=function(){");
sb.Append("alert('");
sb.Append(message);
sb.Append("')};");
sb.Append("</script>");
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", sb.ToString());
}
Namespace:
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
SQL:
CREATE TABLE [dbo].[QuestionTable](
[QuestionId] [int] IDENTITY(1,1) NOT NULL,
[QuestionDescription] [varchar](max) NOT NULL,
[OptionOne] [varchar](30) NOT NULL,
[OptionTwo] [varchar](30) NOT NULL,
[OptionThree] [varchar](30) NOT NULL,
[OptionFour] [varchar](30) NOT NULL,
[CorrectAnswer] [varchar](20) NOT NULL,
CONSTRAINT [PK_QuestionTable] PRIMARY KEY CLUSTERED
(
[QuestionId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
Thank You.