TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
eswar rao
1.6k
98
19.4k
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["sqlconnstr"].ToString());
// PostBackStr = Page.ClientScript.GetPostBackEventReference(this, "time");
if (!SM1.IsInAsyncPostBack)
{
Session["timeout"] = DateTime.Now.AddMinutes(30).ToString();
}
//if (IsPostBack)
//{
// //string eventArg = Request["__EVENTARGUMENT"];
// //if (eventArg == "time")
// //{
// // Response.Write("Timed out..please try again");
// // //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 = "Name : " + txtName.Text;
int score = Convert.ToInt32(txtScore.Text);
lblScore.Text = "Score : " + Convert.ToString(score);
Session["counter"] = "1";
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 = "select * from Question where slNo=" + no + "";
SqlDataAdapter da2 = new SqlDataAdapter(str, sqlconn);
DataSet ds2 = new DataSet();
da2.Fill(ds2, "Question");
if (ds2.Tables[0].Rows.Count > 0)
{
DataRow dtr;
int i = 0;
while (i < ds2.Tables[0].Rows.Count)
{
dtr = ds2.Tables[0].Rows[i];
Session["Answer"] = Convert.ToString(Convert.ToInt32(dtr["Correct"].ToString()) - 1);
lblQuestion.Text = "Q." + Session["counter"].ToString() + " " + dtr["Question"].ToString();
RblOption.ClearSelection();
RblOption.Items.Clear();
RblOption.Items.Add(dtr["Option1"].ToString());
RblOption.Items.Add(dtr["Option2"].ToString());
RblOption.Items.Add(dtr["Option3"].ToString());
RblOption.Items.Add(dtr["Option4"].ToString());
i++;
}
}
}
//public void GetPrevQuestion(int prev)
//{
// // dtr = (DataTable)ViewState["Datatable"];
// // dr = dtr.Rows[prev];
// // //Session["RblOption"] = (string)RblOption.SelectedValue;
// // //RblOption.SelectedValue = (string)Session["RblOption"];
// // lblQuestion.Text = "Q." + Session["counter"] + " " + dr["Qn"].ToString();
// //// RblOption.ClearSelection();
// // RblOption.Items.Clear();
// // RblOption.Items.Add(dr["option1"].ToString());
// // RblOption.Items.Add(dr["option2"].ToString());
// // RblOption.Items.Add(dr["option3"].ToString());
// // RblOption.Items.Add(dr["option4"].ToString());
// if (prev != 0)
// {
// BtnPrev.Visible = true;
// }
// BtnNext.Visible = true;
//}
public void getNextQuestion()
{
if (Convert.ToInt32(Session["counter"].ToString()) < 10)//10 is a counter which is used for 10 questions
{
if (RblOption.SelectedIndex >= 0)
{
if (Session["Answer"].ToString() == RblOption.SelectedIndex.ToString())
{
int score = Convert.ToInt32(txtScore.Text) + 1;// 1 for mark for each question
txtScore.Text = score.ToString();
lblScore.Text = "Score : " + Convert.ToString(score);
}
}
Random rnd = new Random();
int i = rnd.Next(1, 10);
//lblQuestion.Text = i.ToString();
getQuestion(i);
Session["counter"] = Convert.ToString(Convert.ToInt32(Session["counter"].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>
Reply
Answers (
0
)
how to create dynamic checkbox using jquery
In Multiview how to restrict multiple time insertion?