Docstoc

radiobutton.docx - DotNetSpider

Document Sample
radiobutton.docx - DotNetSpider Powered By Docstoc
					<div>
<asp:Label ID="Label1" runat="server">Label1</asp:Label>
                &nbsp;&nbsp;
                <asp:Label ID="Label2" runat="server">Label2</asp:Label>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <br />
                <asp:RadioButtonList ID="RadioButtonList1" runat="server"
            AutoPostBack="True"
            onselectedindexchanged="RadioButtonList1_SelectedIndexChanged">
        </asp:RadioButtonList>
                &nbsp;&nbsp;&nbsp;&nbsp;
        <br />
        <br />
        <asp:Button ID="PrevButton" runat="server" onclick="PrevButton_Click"
            Text="Prev" Visible="False" />
&nbsp;&nbsp;&nbsp;

                <asp:Button ID="NextButton" runat="server"
onclick="NextButton_Click"
            Text="Next" />
        &nbsp;&nbsp;&nbsp;
                <asp:Button ID="SubmitTestButton" runat="server" Text="Submit
Test"
            onclick="SubmitTestButton_Click1" Visible="False" />
                <br />
        <br />
</div>
.aspx.cs

protected void Page_Load(object sender, EventArgs e)
    {

        test=Session["userchoicetest"].ToString();
        if (test.Equals("C"))
            tablename = "ATestC";
        if (test.Equals("C++"))
            tablename = "ATestCPP";
        if (test.Equals("Java"))
            tablename = "ATestJava";
        if (test.Equals(".NET"))
            tablename = "ATestDNET";
        if (!Page.IsPostBack)
        {
            string[] str = new string[4];
            SqlConnection con = new SqlConnection("Data
Source=(local);Initial Catalog=rajannew;User Id=sa;Password=cybage@123");
            con.Open();
            SqlCommand cmd = new SqlCommand("select * from "+tablename+"
where serial=1", con);
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                Label1.Text = dr[0].ToString();
                Label2.Text = dr[1].ToString();
                str[0] = dr[2].ToString();
                str[1] = dr[3].ToString();
                str[2] = dr[4].ToString();
                str[3] = dr[5].ToString();
                Session["ans"] = dr[6].ToString();

               }
               con.Close();
               RadioButtonList1.DataSource = str;
               RadioButtonList1.DataBind();

               Session["qno"] = 1;
               con.Close();
           }


    }
    protected void SubmitTestButton_Click1(object sender, EventArgs e)
    {
        int temp = 0;



         for (int j = 0; j < 5; j++)
         {
              if (score[j] == 1)
                  temp++;
         }
         Session["temp"] = temp;
         float per=(temp*100)/5;
         Session["per"]=per;
         if (per >= 60)
              Session["result"] = "Pass";
         else
              Session["result"]="Fail";



        Response.Redirect("markspage.aspx");
    }

     public void getdata(int i1)
     {
         string[] str = new string[4];
         SqlConnection con = new SqlConnection("data source=(local);Initial
Catalog=rajannew;user id=sa;password=cybage@123");
         con.Open();
         SqlCommand cmd1 = new SqlCommand("select * from "+tablename+" where
serial='" + i1 + "'", con);
         SqlDataReader dr = cmd1.ExecuteReader();
         while (dr.Read())
         {
             Label1.Text = dr[0].ToString();
             Label2.Text = dr[1].ToString();
             str[0] = dr[2].ToString();
             str[1] = dr[3].ToString();
             str[2] = dr[4].ToString();
             str[3] = dr[5].ToString();
             Session["ans"] = dr[6].ToString();


         }

         con.Close();
         RadioButtonList1.DataSource = str;
         RadioButtonList1.DataBind();
         Session["qno"] = i1;
    }

    protected void NextButton_Click(object sender, EventArgs e)
    {


         i++;
         if (i >= 2 && i <= 4)
              PrevButton.Visible = true;
         if (i == 5)
         {
              NextButton.Visible = false;
              PrevButton.Visible = true;
              SubmitTestButton.Visible = true;
         }
         getdata(i);



     }
     protected void RadioButtonList1_SelectedIndexChanged(object sender,
EventArgs e)
     {
         if ((RadioButtonList1.SelectedIndex == 0) &&
(Convert.ToInt32(Session["ans"].ToString()) == 1))
             score[Convert.ToInt32(Session["qno"].ToString()) - 1] = 1;

         if ((RadioButtonList1.SelectedIndex == 1) &&
(Convert.ToInt32(Session["ans"].ToString()) == 2))
             score[Convert.ToInt32(Session["qno"].ToString()) - 1] = 1;

         if ((RadioButtonList1.SelectedIndex == 2) &&
(Convert.ToInt32(Session["ans"].ToString()) == 3))
             score[Convert.ToInt32(Session["qno"].ToString()) - 1] = 1;

         if ((RadioButtonList1.SelectedIndex == 3) &&
(Convert.ToInt32(Session["ans"].ToString()) == 4))
             score[Convert.ToInt32(Session["qno"].ToString()) - 1] = 1;
     }

    protected void PrevButton_Click(object sender, EventArgs e)
     {
         i--;
         getdata(i);
     }
}

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:2
posted:2/29/2012
language:
pages:5