各位大哥,小弟最近在做在线考试系统,遇到大麻烦了,那就是保存不了试卷答案了。
试卷随机生成的,每次刷新的页面都不同,题目是通过Tabel控件生成的,题目内容和选项都是添加用户控件生成的代码。
问题是选择的答案不知道怎么传到后台去,因为后台找不到这些用户控件。请大哥们帮帮忙呀!
看一下代码吧:
//////////////////////////////////////////////////////////////////////////
///用于显示单选题的题目
/////////////////////////////////////////////////////////////////////////
// Total number of rows
int rowCnt;
// Current row count
int rowCtr;
//Examing myclass=new Examing();
//DataTable mytable=myclass.GetExamRadioTitle(getDataBase,"1");
rowCnt = adminExamType.GetExamTypeTotal("单选题");
//cellCnt = 1;
for(rowCtr=0; rowCtr < rowCnt; rowCtr++)
{
TableRow tRow = new TableRow();
ccc.Rows.Add(tRow);
TableCell tCell=new TableCell();
tRow.Cells.Add(tCell);
tCell.Controls.Add(new Label());
System.Web.UI.WebControls.Label Label1=new Label();
Label1.Text=(rowCtr+1).ToString()+"、"+arrtitle[rowCtr,0];
tCell.Controls.Add(Label1);
tCell.Controls.Add(new RadioButtonList());
System.Web.UI.WebControls.RadioButtonList RadioButtonList1=new RadioButtonList();
ListItem SelectA = new ListItem(arrtitle[rowCtr,1]);
ListItem SelectB = new ListItem(arrtitle[rowCtr,2]);
ListItem SelectC = new ListItem(arrtitle[rowCtr,3]);
ListItem SelectD = new ListItem(arrtitle[rowCtr,4]);
RadioButtonList1.Items.Add(SelectA);
RadioButtonList1.Items.Add(SelectB);
RadioButtonList1.Items.Add(SelectC);
RadioButtonList1.Items.Add(SelectD);
RadioButtonList1.RepeatColumns = 4;
RadioButtonList1.RepeatDirection = RepeatDirection.Horizontal;
tCell.Controls.Add(RadioButtonList1);
}
ccc是Table控件,SelectA...SelectD分别是选项ABCD.arrtitle是数据库中读取的选项内容.
请问怎么保存呀?这个问题我想了几天,都没有办法解决,如果不解决偶的毕业设计就过不了关了.
救救俺吧!
怎么没有人回答呀!
我真的是没有办法了!大哥们帮帮忙吧!
循环表格,每次判断此表格里面的控件,取值
for(int i=0;i<this.table.rows.count;i++)
{
RadioButtonList myradio = (RadioButtonList)this.table.rows[i].Findcontrol(0);
}
手写,语法不一定对,大意如此.你最好在生成的时候单选框要命名,之后就可以用名字取Findcontrol("名字");
怎么个动态生成的控件命名?
选项也是动态添加的!
到底怎么做呀!大哥帮帮忙吧!
后台代码
RadioButtonList rbl = new RadioButtonList();
PlaceHoder.Add(rbl)
呵呵,我用的是datalist,里边放radiobuttonlist,我也正在做这个项目。
tCell.Controls.Add(RadioButtonList1);
这样不是一样的吗?
免费培训信息
本周六(4月16日)软件工程师班免费听讲(可以免费听三天课程)。系列课程由浅入深针
对无软件开发基础,且有志于从事IT行业的人。感兴趣者,请速致电010-51607418定
座。(详情请登陆http://www.zhihuigu.com 和 http://www.zhihuigu.net)
特邀著名IT专家,Microsft,Sun高级技术培训师吕智良先生现场授课。座位有限,有
兴趣者请在本周四之前电话定位。
第一天课程:Windows Server 2003 的配置与管理
课程安排如下:
第一天部分课程安排如下:
PPT1
内容提要
基本概念介绍(硬件/软件/操作系统)
Microsoft操作系统的发展历程
Windows Server 2003的安装
PPT2
软件、硬件、操作系统概念和分类
微软公司(Microsoft)操作系统的发展
家庭用户
DOS (Disk Operating System) – 磁盘操作系统
Windows 3.x – 视窗操作系统
Windows 95 – 视窗95
Windows 98 – 视窗98
Windows ME (Millennium ) – 视窗千年版
Windows XP Home Edition – XP家庭版
商业用户
Windows NT Server/Windows NT Workstation
Windows 2000 Server/Windows 2000 Professional
Windows Server 2003/Windows XP Professional
PPT3
实战项目: 安装 Windows Server 2003 企业版
形式:两人一组,参考书上(P12-P32)协商讨论完成。
提供的资源:
VMVare 5.0 虚拟机系统
Alcohol 120%虚拟光驱软件
Windows Server 2003 企业版镜像磁盘文件
助教现场指导答疑
时间:2个小时
此实战项目的意义
熟悉Windows Server 2003的完整安装过程
熟悉使用VMVare 5.0虚拟机软件系统
熟悉使用Alcohol 120%虚拟光驱软件
增加实际动手能力和团队协作能力
PPT4
本章总结
本章主要介绍一些基本的概念,了解 Microsoft Windows 一系列操作系统的发展
过程。最后通过实际安装Windows Server 2003,以加深对该操作系统的理解并掌握
VMWare和Alcohol 120%等常用工具软件的使用。
本章书本上内容理论部分太深,涉及面太广,而且和实际工作联系不是很紧密,不建议
学生全文阅读。
智慧谷程序员俱乐部广聚各路好手!
www.zhihuigu.com
我这样做的
private void Bsave_Click(object sender, System.EventArgs e)
{
string sql,xzjg,wrong,th;
int label=0;
wrong="";
for(int j=0;j<DataList1.Items.Count;j++)
{
RadioButtonList tmpList = (RadioButtonList)DataList1.Items[j].FindControl("RadioButtonList2");
if(tmpList.SelectedIndex>-1)
{
th=((Label)DataList1.Items[j].FindControl("Lth")).Text;
xzjg = tmpList.SelectedItem.Text.Substring(0,1);
TextBox1.Text+=th+xzjg;}
else
{ TextBox1.Text+="0";
wrong+=(j+1)+",";
label=1;
//Response.Write("<script language='JavaScript'>alert('你第'+'"+j+"'+'题还没有回答,一定要交卷吗?');</script>");
}
sql="insert into";
}
if(label==1)
{
Response.Write("<script javascript='JavaScript'> confirm('第'+'"+wrong+"'+'题还没有回答,一定要交卷吗?');</script>");
}
}
up
能把前台代码贴上来看看吗?
前台很简单,下边是单选题的前台代码。
<%@ Page language="c#" Codebehind="one.aspx.cs" AutoEventWireup="false" Inherits="ksxt1._0.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio 7.0" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<TABLE id="Table1" cellSpacing="1" cellPadding="1" width="778" align="center" border="0">
<TR>
<TD><asp:label id="Label1" runat="server">一、选择题</asp:label></TD>
</TR>
<TR>
<TD><FONT face="宋体"><asp:datalist id="DataList1" runat="server" Width="100%" Font-Size="Smaller">
<ItemTemplate>
<FONT face="宋体">
<P>
<asp:Label id=Lid runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "xh") %>'>
</asp:Label>
<asp:Label id=Lth runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "th") %>' Visible="False">
</asp:Label>
<asp:Label id=Llr runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "lr") %>'>
</asp:Label></P>
<P>
<asp:RadioButtonList id="RadioButtonList2" runat="server" Font-Size="X-Small"></asp:RadioButtonList></P>
</FONT>
</ItemTemplate>
</asp:datalist></FONT></TD>
</TR>
<TR>
<TD><FONT face="宋体"><asp:linkbutton id="lnkfirst" onclick="lnkUrl_Change" runat="server" CommandArgument="first">首页</asp:linkbutton><asp:linkbutton id="lnkprev" onclick="lnkUrl_Change" runat="server" CommandArgument="prev">前一页</asp:linkbutton><asp:linkbutton id="lnknext" onclick="lnkUrl_Change" runat="server" CommandArgument="next">下一页</asp:linkbutton><asp:linkbutton id="lnklast" onclick="lnkUrl_Change" runat="server" CommandArgument="last">末页</asp:linkbutton></FONT></TD>
</TR>
<TR>
<TD><FONT face="宋体"><asp:textbox id="TextBox1" runat="server"></asp:textbox><asp:button id="Bsave" runat="server" Width="43px" Text="保存"></asp:button><asp:label id="Lmessage" runat="server"></asp:label></FONT></TD>
</TR>
</TABLE>
</form>
</body>
</HTML>
你写的一次只有一个题目是不是的?
我的题目都是随机出来的,并且题量也是根据数据库中来提取的.
这样我该怎么做!谢谢!
我也做考试系统,QQ34918861
+我,我也遇到了一些问题,34918861
记录题,我是直接用table.control做的.上面有讲
我这样写的,但是出错了。
private void btnSend_Click(object sender, System.EventArgs e)
{
//
for(int i=0;i<this.ccc.Rows.Count;i++)
{
RadioButtonList myradio = (RadioButtonList)this.ccc.Rows[i].FindControl("RadioButtonList1");
for(int j=0;j<4;j++)
{
if(myradio.Items[j].Selected==true)
{
Response.Write(j);
}
Response.Write("<br/>");
}
}
}
出现的错误是:
未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
源错误:
行 267:for(int j=0;j<4;j++)
行 268:{
行 269:if(myradio.Items[j].Selected==true)
行 270:{
行 271:Response.Write(j);
这样是怎么回事,怎么解决?
你如果是页面上手工添加控件,那就简单了,直接取该控件的名字即可.
for(int i=0;i<this.datalist.rows.count;i++)
{
RadioButtonList myradio = (RadioButtonList)this.datalist.rows[i].FindControl("页面控件名称")
for(int j=0;j<myradio.items.count;j++)
{
if(myradio.items[j].selected == true)
{
response.write(j);
}
}
}
学习 + 帮你顶一下
System.Web.UI.WebControls.RadioButtonList RadioButtonList1=new RadioButtonList();
这就是我手动添加的控件
但是出现了上面的问题!帮忙看看!
我不是页面上手工添加控件
是后台代码中加的,该怎么做?
试卷随机生成的,每次刷新的页面都不同,题目是通过Tabel控件生成的,题目内容和选项都是添加用户控件生成的代码。
问题是选择的答案不知道怎么传到后台去,因为后台找不到这些用户控件。请大哥们帮帮忙呀!
看一下代码吧:
//////////////////////////////////////////////////////////////////////////
///用于显示单选题的题目
/////////////////////////////////////////////////////////////////////////
// Total number of rows
int rowCnt;
// Current row count
int rowCtr;
//Examing myclass=new Examing();
//DataTable mytable=myclass.GetExamRadioTitle(getDataBase,"1");
rowCnt = adminExamType.GetExamTypeTotal("单选题");
//cellCnt = 1;
for(rowCtr=0; rowCtr < rowCnt; rowCtr++)
{
TableRow tRow = new TableRow();
ccc.Rows.Add(tRow);
TableCell tCell=new TableCell();
tRow.Cells.Add(tCell);
tCell.Controls.Add(new Label());
System.Web.UI.WebControls.Label Label1=new Label();
Label1.Text=(rowCtr+1).ToString()+"、"+arrtitle[rowCtr,0];
tCell.Controls.Add(Label1);
tCell.Controls.Add(new RadioButtonList());
System.Web.UI.WebControls.RadioButtonList RadioButtonList1=new RadioButtonList();
ListItem SelectA = new ListItem(arrtitle[rowCtr,1]);
ListItem SelectB = new ListItem(arrtitle[rowCtr,2]);
ListItem SelectC = new ListItem(arrtitle[rowCtr,3]);
ListItem SelectD = new ListItem(arrtitle[rowCtr,4]);
RadioButtonList1.Items.Add(SelectA);
RadioButtonList1.Items.Add(SelectB);
RadioButtonList1.Items.Add(SelectC);
RadioButtonList1.Items.Add(SelectD);
RadioButtonList1.RepeatColumns = 4;
RadioButtonList1.RepeatDirection = RepeatDirection.Horizontal;
tCell.Controls.Add(RadioButtonList1);
}
ccc是Table控件,SelectA...SelectD分别是选项ABCD.arrtitle是数据库中读取的选项内容.
请问怎么保存呀?这个问题我想了几天,都没有办法解决,如果不解决偶的毕业设计就过不了关了.
救救俺吧!
怎么没有人回答呀!
我真的是没有办法了!大哥们帮帮忙吧!
循环表格,每次判断此表格里面的控件,取值
for(int i=0;i<this.table.rows.count;i++)
{
RadioButtonList myradio = (RadioButtonList)this.table.rows[i].Findcontrol(0);
}
手写,语法不一定对,大意如此.你最好在生成的时候单选框要命名,之后就可以用名字取Findcontrol("名字");
怎么个动态生成的控件命名?
选项也是动态添加的!
到底怎么做呀!大哥帮帮忙吧!
后台代码
RadioButtonList rbl = new RadioButtonList();
PlaceHoder.Add(rbl)
呵呵,我用的是datalist,里边放radiobuttonlist,我也正在做这个项目。
tCell.Controls.Add(RadioButtonList1);
这样不是一样的吗?
免费培训信息
本周六(4月16日)软件工程师班免费听讲(可以免费听三天课程)。系列课程由浅入深针
对无软件开发基础,且有志于从事IT行业的人。感兴趣者,请速致电010-51607418定
座。(详情请登陆http://www.zhihuigu.com 和 http://www.zhihuigu.net)
特邀著名IT专家,Microsft,Sun高级技术培训师吕智良先生现场授课。座位有限,有
兴趣者请在本周四之前电话定位。
第一天课程:Windows Server 2003 的配置与管理
课程安排如下:
第一天部分课程安排如下:
PPT1
内容提要
基本概念介绍(硬件/软件/操作系统)
Microsoft操作系统的发展历程
Windows Server 2003的安装
PPT2
软件、硬件、操作系统概念和分类
微软公司(Microsoft)操作系统的发展
家庭用户
DOS (Disk Operating System) – 磁盘操作系统
Windows 3.x – 视窗操作系统
Windows 95 – 视窗95
Windows 98 – 视窗98
Windows ME (Millennium ) – 视窗千年版
Windows XP Home Edition – XP家庭版
商业用户
Windows NT Server/Windows NT Workstation
Windows 2000 Server/Windows 2000 Professional
Windows Server 2003/Windows XP Professional
PPT3
实战项目: 安装 Windows Server 2003 企业版
形式:两人一组,参考书上(P12-P32)协商讨论完成。
提供的资源:
VMVare 5.0 虚拟机系统
Alcohol 120%虚拟光驱软件
Windows Server 2003 企业版镜像磁盘文件
助教现场指导答疑
时间:2个小时
此实战项目的意义
熟悉Windows Server 2003的完整安装过程
熟悉使用VMVare 5.0虚拟机软件系统
熟悉使用Alcohol 120%虚拟光驱软件
增加实际动手能力和团队协作能力
PPT4
本章总结
本章主要介绍一些基本的概念,了解 Microsoft Windows 一系列操作系统的发展
过程。最后通过实际安装Windows Server 2003,以加深对该操作系统的理解并掌握
VMWare和Alcohol 120%等常用工具软件的使用。
本章书本上内容理论部分太深,涉及面太广,而且和实际工作联系不是很紧密,不建议
学生全文阅读。
智慧谷程序员俱乐部广聚各路好手!
www.zhihuigu.com
我这样做的
private void Bsave_Click(object sender, System.EventArgs e)
{
string sql,xzjg,wrong,th;
int label=0;
wrong="";
for(int j=0;j<DataList1.Items.Count;j++)
{
RadioButtonList tmpList = (RadioButtonList)DataList1.Items[j].FindControl("RadioButtonList2");
if(tmpList.SelectedIndex>-1)
{
th=((Label)DataList1.Items[j].FindControl("Lth")).Text;
xzjg = tmpList.SelectedItem.Text.Substring(0,1);
TextBox1.Text+=th+xzjg;}
else
{ TextBox1.Text+="0";
wrong+=(j+1)+",";
label=1;
//Response.Write("<script language='JavaScript'>alert('你第'+'"+j+"'+'题还没有回答,一定要交卷吗?');</script>");
}
sql="insert into";
}
if(label==1)
{
Response.Write("<script javascript='JavaScript'> confirm('第'+'"+wrong+"'+'题还没有回答,一定要交卷吗?');</script>");
}
}
up
能把前台代码贴上来看看吗?
前台很简单,下边是单选题的前台代码。
<%@ Page language="c#" Codebehind="one.aspx.cs" AutoEventWireup="false" Inherits="ksxt1._0.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio 7.0" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<TABLE id="Table1" cellSpacing="1" cellPadding="1" width="778" align="center" border="0">
<TR>
<TD><asp:label id="Label1" runat="server">一、选择题</asp:label></TD>
</TR>
<TR>
<TD><FONT face="宋体"><asp:datalist id="DataList1" runat="server" Width="100%" Font-Size="Smaller">
<ItemTemplate>
<FONT face="宋体">
<P>
<asp:Label id=Lid runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "xh") %>'>
</asp:Label>
<asp:Label id=Lth runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "th") %>' Visible="False">
</asp:Label>
<asp:Label id=Llr runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "lr") %>'>
</asp:Label></P>
<P>
<asp:RadioButtonList id="RadioButtonList2" runat="server" Font-Size="X-Small"></asp:RadioButtonList></P>
</FONT>
</ItemTemplate>
</asp:datalist></FONT></TD>
</TR>
<TR>
<TD><FONT face="宋体"><asp:linkbutton id="lnkfirst" onclick="lnkUrl_Change" runat="server" CommandArgument="first">首页</asp:linkbutton><asp:linkbutton id="lnkprev" onclick="lnkUrl_Change" runat="server" CommandArgument="prev">前一页</asp:linkbutton><asp:linkbutton id="lnknext" onclick="lnkUrl_Change" runat="server" CommandArgument="next">下一页</asp:linkbutton><asp:linkbutton id="lnklast" onclick="lnkUrl_Change" runat="server" CommandArgument="last">末页</asp:linkbutton></FONT></TD>
</TR>
<TR>
<TD><FONT face="宋体"><asp:textbox id="TextBox1" runat="server"></asp:textbox><asp:button id="Bsave" runat="server" Width="43px" Text="保存"></asp:button><asp:label id="Lmessage" runat="server"></asp:label></FONT></TD>
</TR>
</TABLE>
</form>
</body>
</HTML>
你写的一次只有一个题目是不是的?
我的题目都是随机出来的,并且题量也是根据数据库中来提取的.
这样我该怎么做!谢谢!
我也做考试系统,QQ34918861
+我,我也遇到了一些问题,34918861
记录题,我是直接用table.control做的.上面有讲
我这样写的,但是出错了。
private void btnSend_Click(object sender, System.EventArgs e)
{
//
for(int i=0;i<this.ccc.Rows.Count;i++)
{
RadioButtonList myradio = (RadioButtonList)this.ccc.Rows[i].FindControl("RadioButtonList1");
for(int j=0;j<4;j++)
{
if(myradio.Items[j].Selected==true)
{
Response.Write(j);
}
Response.Write("<br/>");
}
}
}
出现的错误是:
未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
源错误:
行 267:for(int j=0;j<4;j++)
行 268:{
行 269:if(myradio.Items[j].Selected==true)
行 270:{
行 271:Response.Write(j);
这样是怎么回事,怎么解决?
你如果是页面上手工添加控件,那就简单了,直接取该控件的名字即可.
for(int i=0;i<this.datalist.rows.count;i++)
{
RadioButtonList myradio = (RadioButtonList)this.datalist.rows[i].FindControl("页面控件名称")
for(int j=0;j<myradio.items.count;j++)
{
if(myradio.items[j].selected == true)
{
response.write(j);
}
}
}
学习 + 帮你顶一下
System.Web.UI.WebControls.RadioButtonList RadioButtonList1=new RadioButtonList();
这就是我手动添加的控件
但是出现了上面的问题!帮忙看看!
我不是页面上手工添加控件
是后台代码中加的,该怎么做?