如何在ASP.NET和C#中为在线考试网站生成result.aspx页面 [英] How do I generate the result.aspx page for online examination website in ASP.NET and C#

查看:93
本文介绍了如何在ASP.NET和C#中为在线考试网站生成result.aspx页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好每个我想创建asp.net和c#在线考试网站这里是我的exam.aspx点击提交按钮我想通过乘以result.aspx页面中的标记来计算结果请帮我生成这个结果谢谢



我尝试过:



< asp :Content ID =Content1ContentPlaceHolderID =headRunat =Server>



.auto-style1 {

width: 100%;

}





< asp:Content ID =Content2ContentPlaceHolderID =content Runat =Server>



< asp:Label ID =subjectLabelrunat =serverText =主题:>


< asp:Label runat =serverText =剩余时间:>


< asp:SqlDataSource ID =SqlDataSource1runat =serverConnectionString =<%$ ConnectionStrings:RegistrationConnectionString2 %>中SelectCommand =SELECT * FROM [Biology]>









< asp:DataList ID =DataList1runat =serverDataKeyField =IdDataSourceID =SqlDataSource1>

< itemtemplate>

< br $>




问题

< asp:Label ID =Label1runat =serverText ='<%#Eval(Id)%>'>

 :

< asp:Label ID =Label2runat =serverText ='<%#Eval(Question)%>'>




< asp:RadioButton GroupName =ansID =RadioButton1runat =serverText ='<%#Eval(Option1)%>'/>




< asp:RadioButton GroupName =ansID =RadioButton2runat =serverText ='<%#Eval(Option2)%>'/> ;




< asp:RadioButton GroupName =ansID =RadioButton3runat =serverText ='<%#Eval( Option3)%>'/>




< asp:RadioButton GroupName =ID =RadioButton4runat =serverText = '<%#Eval(Option4)%>'/>







解决方案

ConnectionStrings:RegistrationConnectionString2%>SelectCommand =SELECT * FROM [Biology]>









< asp:DataList ID =DataList1 runat =serverDataKeyField =IdDataSourceID =SqlDataSource1>

< itemtemplate>







问题

< asp:标签ID =Label1runat =serverText ='<%#Eval(Id)%>'>

 :

< asp:Label ID =Label2runat =serverText ='<%#Eval(Question)%> '>




< asp:RadioButton GroupName =ansID =RadioButton1runat =serverText ='<%#Eval (Option1)%>'/>




< asp:RadioButton GroupName =ansID =RadioButton2runat =server Text ='<%#Eval(Option2)%>'/>




< asp:RadioButton GroupName =ansID =RadioButton3runat =serverText ='<%#Eval(Option3)%>'/>




< asp:RadioButton GroupName =ID =RadioButton4runat =serverText ='<%#Eval(Option4)%>'/> ;








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();





你的代码需要一些清理。首先,习惯于放置食用资源的对象,例如 SqlConnection SqlCommand SqlDataAdapter 使用语句中,以确保在使用对象后正确处理和关闭对象。



其次,将值直接附加到SQL查询是一个不可能,因为它可能导致SQL注入攻击。使用参数化查询可以避免这种情况发生:保护您的数据:防止SQL注入 [ ^ ]



第三,创建一种获取数据的通用方法,而不是执行完成相同工作的相同代码。

例如,您可以创建一个通用且可重用的方法,返回 DataTable ,如下所示:



  public  DataTable GetData( string  param1, string  param2){
DataTable dt = new DataTable();
string sqlStatement = SELECT ColumnName FROM YourTableName WHERE ColumnName = @ Param1 AND ColumnName = @ Param2;

使用(SqlConnection connection = new SqlConnection(GetConnectionString())){
使用(SqlCommand cmd = new SqlCommand(sqlStatement,connection)){
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue( @ Param1,param1);
cmd.Parameters.AddWithValue( @ Param2,param2);
使用(SqlDataAdapter da = new SqlDataAdapter(cmd)){
da。补(DT);
}
}
}
return dt;
}





第四,做一个简单的计算非常简单。你只需要了解自己在做什么并从中开始。你是唯一能够做到这一点的人,因为你是那个知道这个公式的人。



最后,如果你没有得到你期望的输出,请使用调试器。在您要查看的方法中设置一个断点,然后逐步进入每一行以确定发生了什么。请参阅使用Visual Studio导航代码调试器 - Visual Studio | Microsoft Docs [ ^ ]


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") %>' />




解决方案

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") %>' />





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[^]


这篇关于如何在ASP.NET和C#中为在线考试网站生成result.aspx页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆