我将使用c#在asp.net中构建在线考试系统。我已经创建了一个在线考试的向导,但每当我进入下一步然后回到上一步,我发现所选择的radiobuttonr仍未被选中。为什么会这样?什么是解决方案?
我还想问一个问题: - 我可以在每个步骤的顶部放置计时器,考试名称和总分,而不必在向导控制的每一步中重复它吗? 如果是,那怎么办?
以下是向导第一步的.cs代码: -
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
public partial class Demo : System.Web.UI.Page
{
SqlConnection con;
public Demo()
{
con = new SqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void wizard1(Object sender, System.EventArgs e)
{
SqlDataAdapter adp = new SqlDataAdapter("select top 10 Question,Option1,Option2,Option3,Option4 from Questions", con);
DataTable dt = new DataTable();
adp.Fill(dt);
Repeater1.DataSource = dt;
Repeater1.DataBind();
}
}
以下是.aspx代码: -
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Demo.aspx.cs" Inherits="Demo" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Wizard ID="Wizard1" runat="server" BackColor="#E6E2D8" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" Height="433px" Width="581px">
<HeaderStyle BackColor="#666666" BorderColor="#E6E2D8" BorderStyle="Solid" BorderWidth="2px" Font-Bold="True" Font-Size="0.9em" ForeColor="White" HorizontalAlign="Center" />
<NavigationButtonStyle BackColor="White" BorderColor="#C5BBAF" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#1C5E55" />
<SideBarButtonStyle ForeColor="White" />
<SideBarStyle BackColor="#1C5E55" Font-Size="0.9em" VerticalAlign="Top" />
<StepStyle BackColor="#F7F6F3" BorderColor="#E6E2D8" BorderStyle="Solid" BorderWidth="2px" />
<WizardSteps>
<asp:WizardStep runat="server" Title="Instructions">
Click next and start your exam!!!
</asp:WizardStep>
<asp:WizardStep ID="WizardStep1" runat="server" Title="Reasoning" OnActivate="wizard1">
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<table border=1>
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="1"></asp:Label>
</td>
<td>
<%#DataBinder.Eval(Container.DataItem,"Question") %>
</td>
</tr>
<tr>
<td></td>
<td><asp:RadioButton ID="RadioButton1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Option1")%>' /></td>
</tr>
<tr>
<td></td>
<td><asp:RadioButton ID="RadioButton2" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Option2")%>' /></td>
</tr>
<tr>
<td></td>
<td><asp:RadioButton ID="RadioButton3" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Option3")%>' /></td>
</tr>
<tr>
<td></td>
<td><asp:RadioButton ID="RadioButton4" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Option4")%>' /></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</asp:WizardStep>
<asp:WizardStep ID="WizardStep2" runat="server" Title="Quantitative Aptitude"></asp:WizardStep>
<asp:WizardStep runat="server" Title="English">
</asp:WizardStep>
<asp:WizardStep runat="server" Title="Mathematics">
</asp:WizardStep>
<asp:WizardStep runat="server" Title="Computer Concepts">
</asp:WizardStep>
</WizardSteps>
</asp:Wizard>
</div>
</form>
</body>
</html>
答案 0 :(得分:1)
不需要&#34; protected void wizard1(Object sender,System.EventArgs e)&#34;。删除它。
创建一个fill()方法并绑定该函数中的数据。
public void fill()
{
SqlDataAdapter adp = new SqlDataAdapter("select top 10 Question,Option1,Option2,Option3,Option4 from Questions", con);
DataTable dt = new DataTable();
adp.Fill(dt);
Repeater1.DataSource = dt;
Repeater1.DataBind();
}
在Page_load添加条件
中非常重要 if (!IsPostBack)
{
fill();
}