Click here to Skip to main content
14,029,747 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
hello every one i want to create asp.net and c# online examination website here is my exam.aspx after clicking submit button i want to calculate the result by multiplying the marks in the result.aspx page please help me to generate this result thank you

What I have tried:

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

.auto-style1 {
width: 100%;
}


<asp:Content ID="Content2" ContentPlaceHolderID="content" Runat="Server">


<asp:Label ID="subjectLabel" runat="server" Text="Subject :">

<asp:Label runat="server" Text="Time Remaining : ">

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:RegistrationConnectionString2 %>" SelectCommand="SELECT * FROM [Biology]">




<asp:DataList ID="DataList1" runat="server" DataKeyField="Id" DataSourceID="SqlDataSource1">
<itemtemplate>



Question
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Id") %>'>
 :
<asp:Label ID="Label2" runat="server" Text='<%# Eval("Question") %>'>


<asp:RadioButton GroupName="ans" ID="RadioButton1" runat="server" Text='<%# Eval("Option1") %>' />


<asp:RadioButton GroupName="ans" ID="RadioButton2" runat="server" Text='<%# Eval("Option2") %>' />


<asp:RadioButton GroupName="ans" ID="RadioButton3" runat="server" Text='<%# Eval("Option3") %>' />


<asp:RadioButton GroupName="" ID="RadioButton4" runat="server" Text='<%# Eval("Option4") %>' />




Posted
Updated 29-Nov-18 19:34pm
Comments
CHill60 29-Nov-18 12:00pm
   
It doesn't look as if you have made any attempt to calculate the result. Post that code and tell us what the problem is.
AhmedHosny96 29-Nov-18 13:29pm
   
brother i can show u my code behind but what i want is to calculate the result and display the percentage help me please ? thanks in advance <3

protected void Page_Load(object sender, EventArgs e)
{
//To View Option Selected

SqlDataAdapter da1 = new SqlDataAdapter("SELECT Option" + dt.Rows[0]["Opt_Selected"].ToString() + " FROM " + sub + " WHERE Id=" + dt.Rows[0]["Que_Id"].ToString(), con);
DataTable dt1 = new DataTable();
da1.Fill(dt1);
Label2.Text = dt1.Rows[0]["Option" + dt.Rows[0]["Opt_Selected"].ToString()].ToString();

SqlDataAdapter da2 = new SqlDataAdapter("SELECT Option" + dt.Rows[1]["Opt_Selected"].ToString() + " FROM " + sub + " WHERE Id=" + dt.Rows[1]["Que_Id"].ToString(), con);
DataTable dt2 = new DataTable();
da2.Fill(dt2);
Label5.Text = dt2.Rows[0]["Option" + dt.Rows[1]["Opt_Selected"].ToString()].ToString();

SqlDataAdapter da3 = new SqlDataAdapter("SELECT Option" + dt.Rows[2]["Opt_Selected"].ToString() + " FROM " + sub + " WHERE Id=" + dt.Rows[2]["Que_Id"].ToString(), con);
DataTable dt3 = new DataTable();
da3.Fill(dt3);
Label8.Text = dt3.Rows[0]["Option" + dt.Rows[2]["Opt_Selected"].ToString()].ToString();

SqlDataAdapter da4 = new SqlDataAdapter("SELECT Option" + dt.Rows[3]["Opt_Selected"].ToString() + " FROM " + sub + " WHERE Id=" + dt.Rows[3]["Que_Id"].ToString(), con);
DataTable dt4 = new DataTable();
da4.Fill(dt4);
Label11.Text = dt4.Rows[0]["Option" + dt.Rows[3]["Opt_Selected"].ToString()].ToString();

//To View Right Answer Of The Question

SqlDataAdapter da21 = new SqlDataAdapter("SELECT Option" + dt.Rows[0]["Ans"].ToString() + " FROM " + sub + " WHERE Id=" + dt.Rows[0]["Que_Id"].ToString(), con);
DataTable dt21 = new DataTable();
da21.Fill(dt21);
Label3.Text = dt21.Rows[0]["Option" + dt.Rows[0]["Ans"].ToString()].ToString();

SqlDataAdapter da22 = new SqlDataAdapter("SELECT Option" + dt.Rows[1]["Ans"].ToString() + " FROM " + sub + " WHERE Id=" + dt.Rows[1]["Que_Id"].ToString(), con);
DataTable dt22 = new DataTable();
da22.Fill(dt22);
Label6.Text = dt22.Rows[0]["Option" + dt.Rows[1]["Ans"].ToString()].ToString();

SqlDataAdapter da23 = new SqlDataAdapter("SELECT Option" + dt.Rows[2]["Ans"].ToString() + " FROM " + sub + " WHERE Id=" + dt.Rows[2]["Que_Id"].ToString(), con);
DataTable dt23 = new DataTable();
da23.Fill(dt23);
Label9.Text = dt23.Rows[0]["Option" + dt.Rows[2]["Ans"].ToString()].ToString();

SqlDataAdapter da24 = new SqlDataAdapter("SELECT Option" + dt.Rows[3]["Ans"].ToString() + " FROM " + sub + " WHERE Id=" + dt.Rows[3]["Que_Id"].ToString(), con);
DataTable dt24 = new DataTable();
da24.Fill(dt24);
Label12.Text = dt24.Rows[0]["Option" + dt.Rows[3]["Ans"].ToString()].ToString();
}
ZurdoDev 29-Nov-18 15:29pm
   
What is your question? Right now you are asking "Someone do my work for me." You need to be more specific to where you are stuck.

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Quote:
SqlDataAdapter da1 = new SqlDataAdapter("SELECT Option" + dt.Rows[0]["Opt_Selected"].ToString() + " FROM " + sub + " WHERE Id=" + dt.Rows[0]["Que_Id"].ToString(), con);
DataTable dt1 = new DataTable();
da1.Fill(dt1);
Label2.Text = dt1.Rows[0]["Option" + dt.Rows[0]["Opt_Selected"].ToString()].ToString();


Your code needs some clean up. First off, make it a habit to put objects that eat resources such as SqlConnection, SqlCommand and SqlDataAdapter within a using statement to ensure that objects will be properly disposed and closed after they are used.

Second, appending the values directly to your SQL query is a BIG no no as it can potentially leads to SQL Injection attack. Use parameterize query to avoid that to happen: Protect Your Data: Prevent SQL Injection[^]

Third, create a common method for getting the data instead of doing the same code that does the same job.
For example you could create a common and reusable method that returns a DataTable like this:

public DataTable GetData(string param1, string param2){
       DataTable dt = new DataTable();
	   string sqlStatement = "SELECT ColumnName FROM YourTableName WHERE ColumnName = @Param1 AND ColumnName = @Param2";
   
        	using(SqlConnection connection = new SqlConnection(GetConnectionString())){
           		using(SqlCommand cmd = new SqlCommand(sqlStatement ,connection)){
               	 	cmd.CommandType = CommandType.Text;
       	            cmd.Parameters.AddWithValue("@Param1", param1);
           			cmd.Parameters.AddWithValue("@Param2", param2);
					using(SqlDataAdapter da = new SqlDataAdapter(cmd)){
						da.Fill(dt);
					}
        		}
        }
	return 	dt;	
}


Fourth, doing a simple calculation is pretty much easy. You just need to understand what you are doing and start from that. You're the only one who can do it because you are the one who knows the formula.

Finally, use the debugger if you are not getting the output that you are expecting. Set a break point in the method where you want to look into and step into each line to figure out what's going on. See, Navigate code with the Visual Studio debugger - Visual Studio | Microsoft Docs[^]
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.190419.4 | Last Updated 30 Nov 2018
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100