eswar rao

eswar rao

  • 1.6k
  • 98
  • 19.3k

how change background color when attempt the answer asp.net

Dec 15 2015 4:53 AM
how change background color when attempt the answer using radio button in asp.net
 
hi, i have one challenge, that is i am developing a one online examination website , in that when i am attempt the question ..., have to change the lable 1 back color is green , and when i am click on mark as review button it will shows the orange color ..how can i write code for that please help me...or send a reference url to me..i am waitng for your reply...thank you .
my code is ...
<pre lang="C#">public partial class user_poexam : System.Web.UI.Page
{
protected string PostBackStr;
public static SqlConnection sqlconn;
protected void Page_Load(object sender, EventArgs e)
{
sqlconn = new SqlConnection(ConfigurationManager.AppSettings[&quot;sqlconnstr&quot;].ToString());
// PostBackStr = Page.ClientScript.GetPostBackEventReference(this, &quot;time&quot;);
if (!SM1.IsInAsyncPostBack)
{
Session[&quot;timeout&quot;] = DateTime.Now.AddMinutes(30).ToString();
}
//if (IsPostBack)
//{
// //string eventArg = Request[&quot;__EVENTARGUMENT&quot;];
// //if (eventArg == &quot;time&quot;)
// //{
// // Response.Write(&quot;Timed out..please try again&quot;);
// // //getNextQuestion();
// //}
//}
}
protected void btn_next_Click(object sender, EventArgs e)
{
getNextQuestion();
}
protected void btn_startexam_Click(object sender, EventArgs e)
{
// Label1.Visible = false;
//txtName.Visible = false;
btn_startexam.Visible = false;
Panel1.Visible = true;
// lblName.Text = &quot;Name : &quot; + txtName.Text;
int score = Convert.ToInt32(txtScore.Text);
lblScore.Text = &quot;Score : &quot; + Convert.ToString(score);
Session[&quot;counter&quot;] = &quot;1&quot;;
Random rnd = new Random();
int i = rnd.Next(1, 10);//Here specify your starting slno of question table and ending no.
//lblQuestion.Text = i.ToString();
getQuestion(i);
}
public void getQuestion(int no)
{
string str = &quot;select * from Question where slNo=&quot; + no + &quot;&quot;;
SqlDataAdapter da2 = new SqlDataAdapter(str, sqlconn);
DataSet ds2 = new DataSet();
da2.Fill(ds2, &quot;Question&quot;);
if (ds2.Tables[0].Rows.Count &gt; 0)
{
DataRow dtr;
int i = 0;
while (i &lt; ds2.Tables[0].Rows.Count)
{
dtr = ds2.Tables[0].Rows[i];
Session[&quot;Answer&quot;] = Convert.ToString(Convert.ToInt32(dtr[&quot;Correct&quot;].ToString()) - 1);
lblQuestion.Text = &quot;Q.&quot; + Session[&quot;counter&quot;].ToString() + &quot; &quot; + dtr[&quot;Question&quot;].ToString();
RblOption.ClearSelection();
RblOption.Items.Clear();
RblOption.Items.Add(dtr[&quot;Option1&quot;].ToString());
RblOption.Items.Add(dtr[&quot;Option2&quot;].ToString());
RblOption.Items.Add(dtr[&quot;Option3&quot;].ToString());
RblOption.Items.Add(dtr[&quot;Option4&quot;].ToString());
i++;
}
}
}
//public void GetPrevQuestion(int prev)
//{
// // dtr = (DataTable)ViewState[&quot;Datatable&quot;];
// // dr = dtr.Rows[prev];
// // //Session[&quot;RblOption&quot;] = (string)RblOption.SelectedValue;
// // //RblOption.SelectedValue = (string)Session[&quot;RblOption&quot;];
// // lblQuestion.Text = &quot;Q.&quot; + Session[&quot;counter&quot;] + &quot; &quot; + dr[&quot;Qn&quot;].ToString();
// //// RblOption.ClearSelection();
// // RblOption.Items.Clear();
// // RblOption.Items.Add(dr[&quot;option1&quot;].ToString());
// // RblOption.Items.Add(dr[&quot;option2&quot;].ToString());
// // RblOption.Items.Add(dr[&quot;option3&quot;].ToString());
// // RblOption.Items.Add(dr[&quot;option4&quot;].ToString());
// if (prev != 0)
// {
// BtnPrev.Visible = true;
// }
// BtnNext.Visible = true;
//}
public void getNextQuestion()
{
if (Convert.ToInt32(Session[&quot;counter&quot;].ToString()) &lt; 10)//10 is a counter which is used for 10 questions
{
if (RblOption.SelectedIndex &gt;= 0)
{
if (Session[&quot;Answer&quot;].ToString() == RblOption.SelectedIndex.ToString())
{
int score = Convert.ToInt32(txtScore.Text) + 1;// 1 for mark for each question
txtScore.Text = score.ToString();
lblScore.Text = &quot;Score : &quot; + Convert.ToString(score);
}
}
Random rnd = new Random();
int i = rnd.Next(1, 10);
//lblQuestion.Text = i.ToString();
getQuestion(i);
Session[&quot;counter&quot;] = Convert.ToString(Convert.ToInt32(Session[&quot;counter&quot;].ToString()) + 1);
}
else
{
Panel2.Visible = false;
//code for displaying after completting the exam, if you want to show the result then you can code here.
}
}</pre>
design code:
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" >
<ContentTemplate>
<asp:Label ID="lbl_Timer" runat="server" Text="Label"></asp:Label>
<asp:Button ID="btn_startexam" runat="server" CssClass="btn_examstart" Text="Start Exam" ToolTip="Enter Your Name" OnClick="btn_startexam_Click"/>
<asp:TextBox ID="txtScore" runat="server" Style="z-index: 103; left: 251px; position: relative;
top: 276px" Visible="False" Width="63px">0</asp:TextBox>
<asp:Panel ID="Panel1" runat="server" CssClass="pnl_exam1" Visible="false" >
<asp:Label ID="lblScore" runat="server" CssClass="lbl_score" Text="Score : " ></asp:Label>
<asp:Panel ID="Panel3" runat="server" Height="14px" Width="119px" style="left:427px; z-index: 106; position: relative; top: 2px;">
<span id="cd" style ="left:100px;"></span>
</asp:Panel>
<asp:Panel ID="Panel2" runat="server" CssClass="pnl2_exam" >
<asp:Label ID="lblQuestion" runat="server" CssClass="lblquestion"></asp:Label>
<asp:RadioButtonList ID="RblOption" runat="server" CssClass="rbtnanswer" >
</asp:RadioButtonList>
<asp:Button ID="btn_next" runat="server" CssClass="btn_examnext" Text="Next" ToolTip="Click Here to Save and Take Next Question" OnClick="btn_next_Click" />
<asp:Button ID="btn_mreview" runat="server" CssClass="btn_examreview" Text="Mark as Review" ToolTip="Click Here to Mark as review" />
<asp:Button ID="btn_mans" runat="server" CssClass="btn_exammanswer" Text="Mark as Answer" ToolTip="Click Here to Mark as Answer" />
</asp:Panel>
<asp:Panel ID="Panel4" runat="server" CssClass="pnl_side">
<div id="div_qviewback" style="padding-left:5px; padding-right:5px;">
<asp:Label ID="Label1" runat="server" Text="1" CssClass="lbl_qviews" ></asp:Label>
<asp:Label ID="Label2" runat="server" Text="2" CssClass="lbl_qviews" ></asp:Label>
<asp:Label ID="Label3" runat="server" Text="3" CssClass="lbl_qviews" ></asp:Label>
<asp:Label ID="Label4" runat="server" Text="4" CssClass="lbl_qviews" ></asp:Label>
<asp:Label ID="Label5" runat="server" Text="5" CssClass="lbl_qviews" ></asp:Label>
<asp:Label ID="Label6" runat="server" Text="6" CssClass="lbl_qviews" ></asp:Label>
<asp:Label ID="Label7" runat="server" Text="7" CssClass="lbl_qviews" ></asp:Label>
<asp:Label ID="Label8" runat="server" Text="8" CssClass="lbl_qviews" ></asp:Label>
<asp:Label ID="Label9" runat="server" Text="9" CssClass="lbl_qviews" ></asp:Label>
<asp:Label ID="Label10" runat="server" Text="10" CssClass="lbl_qviews" ></asp:Label>
</div>
</asp:Panel>
</asp:Panel>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="timer1" EventName="tick"/>
</Triggers>
</asp:UpdatePanel>