您的位置:首页 > 编程语言 > ASP

repeater嵌套RadioButtonList

2007-10-11 14:04 302 查看
.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="examineMain.aspx.cs" Inherits="examineMain" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
    <link href="Common/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" language="javascript">

  function   time_(intime)  
  {  
  var   mm,ss,time_all;
  time_all = intime;
  mm=parseInt(time_all/60);  
  ss=time_all   %   60;  
  if(mm<10)   mm='0'+mm;  
  if(ss<10)   ss='0'+ss;  
  str=mm+':'+ss;  
 
  document.all.lbltime.innerText=str;

  if(time_all==0)  
     top.location.href('TimeOver.aspx');
  else
  {  
      time_all=time_all-1;  
      document.all.hidtime.value=time_all;
      setTimeout("time_("+time_all+")",1000);
  }
}
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div style="text-align:center;">
   
<%--
    计时部分开始
--%>
            <table width="1004" border="0" cellpadding="0" cellspacing="0" style="margin-bottom:20px;">
                <tr>
                    <td width="1004" align="left" valign="bottom" background="images/4.gif" style="height: 176px">
                        <table width="424" height="55" border="0" cellspacing="0">
                            <tr>
                                <td width="93" style="height: 54px">
                                     </td>
                                <td width="327" style="height: 54px">
                                    <table width="180" border="0" cellspacing="0" cellpadding="0">
                                        <tr>
                                            <td width="118" background="images/3.gif" align="center">
                                                <asp:Label ID="lbltime" runat="server"></asp:Label>
                                                 <asp:HiddenField ID="hidtime" runat="server" />
                                            </td>
                                            <td width="62">
                                                <img src="images/jishi.gif" width="65" height="31" /></td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2" style="height: 15px">
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
<script type="text/javascript">
    time_(document.all.hidtime.value);
</script>
<%--
    计时部分结束
--%>

<%--
    试题部分开始
--%>
        <asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
            <HeaderTemplate>
                <table width="850">
            </HeaderTemplate>
           
            <ItemTemplate>
                <tr align="left">
                    <td>
                        <asp:Label ID="ID" runat="server"></asp:Label>
                        <asp:Label ID="QUESTION" runat="server"></asp:Label>
                        <asp:Label ID="TYPE" runat="server"></asp:Label>
                    </td>
                </tr>   
                <tr align="left">
                    <td style="cursor:pointer;" onclick="">
                        <asp:RadioButtonList ID="RadList" runat="server">
                        </asp:RadioButtonList>
                       <asp:CheckBoxList ID="ChkList" runat="server">
                        </asp:CheckBoxList>
                     </td>
                </tr>   
            </ItemTemplate>
           
            <FooterTemplate>
                </table>
            </FooterTemplate>
        </asp:Repeater>
<%--
    试题部分结束
--%>
 <table width="850" border="0" cellpadding="0" cellspacing="0" style="margin-top:10px;">
    <tr>
        <td>
            <asp:Button ID="btnNextPage" runat="server" Text="下一页" OnClick="btnNextPage_Click"></asp:Button>
            
        </td>
    </tr>
</table>
   </div>
    </form>
</body>
</html>
 

 

.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class examineMain : System.Web.UI.Page
{
    testSystem.DAL.DAQuestion dq = null;
    static int pageIndex;
    static int boolEnd;
    static int time_all=45*60;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            lbltime.Text = time_all.ToString();
            pageIndex = 1;
            databind(pageIndex);
            hidtime.Value= time_all .ToString() ;
        }
    }

    private void databind(int pageIndex)
    {
            dq = new testSystem.DAL.DAQuestion();
            DataSet ds = dq.getQuestion(pageIndex,out boolEnd);
            Repeater1.DataSource = ds.Tables["question"];
            Repeater1.DataBind();
    }
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
        {
                Label lab = (Label)e.Item.FindControl("ID");
                lab.Text = ((DataRowView)e.Item.DataItem).Row["ID"].ToString()+":";
                lab = (Label)e.Item.FindControl("QUESTION");
                lab.Text = ((DataRowView)e.Item.DataItem).Row["QUESTION"].ToString();

                int flag = Convert.ToInt32(((DataRowView)e.Item.DataItem).Row["type"]);

                DataSet ds = dq.getOptionbyQuestionId(Convert.ToInt32(((DataRowView)e.Item.DataItem).Row["QID"]));
                ArrayList colArrayList = new ArrayList();

                int i = 65;   

                foreach (DataRow dr in ds.Tables["option"].Rows)
                {
                    colArrayList.Add((Convert.ToChar(i)).ToString()+":"+dr["answerOption"].ToString());
                    i++;
                }

                RadioButtonList RadList = (RadioButtonList)e.It
b6ac
em.FindControl("RadList");
                CheckBoxList ChkList = (CheckBoxList)e.Item.FindControl("ChkList");
                RadList.DataSource = colArrayList;
                RadList.DataBind();

                ChkList.DataSource = colArrayList;
                ChkList.DataBind();
              
                lab = (Label)e.Item.FindControl("TYPE");
                if (flag == 0)
                {
                    lab.Text = "<font color=red>(单选题)</font>";
                    RadList.Visible = true;
                    ChkList.Visible = false;
                }
                else
                {
                    lab.Text = "<font color=red>(多选题)</font>";
                    RadList.Visible = false;
                    ChkList.Visible = true;

                }

            }
    }

    protected void btnNextPage_Click(object sender, EventArgs e)
    {
        pageIndex = pageIndex + 1;

        if (boolEnd!=1)
        {
            databind(pageIndex);
           
            hidtime.Value= Request["hidtime"];
        }

        if (boolEnd==1)
        {
            btnNextPage.Text = "提  交";
        }

        for (int i = 0; i < Repeater1.Items.Count; i++)
        {
            CheckBoxList chk = new CheckBoxList();
            chk = (CheckBoxList)Repeater1.Items[i].FindControl("ChkList");
            string result = "";
            foreach (ListItem li in chk.Items)
            {
                if (li.Selected)
                {
                    result = result + li.Text + "|";
                }
            }
            if (result!="")
            {
                Response.Write(result);
                Response.End();
            }
        }
    }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息