repeater嵌套RadioButtonList

原创 2007年10月11日 14:04:00

.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">
                                    &nbsp;</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>
                                                &nbsp;<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.Item.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();
            }
        }
    }
}

repeater嵌套RadioButtonList

.aspxhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">http://www.w3.org/1999/xhtml" >       ...
  • JOEMAIL
  • JOEMAIL
  • 2007-10-11 14:04:00
  • 2385

RadioButtonList绑定后台数据,触发点击事件

首先前台页面放置一个RadioButtonList 控件                         RepeatLayout="Flow" AutoPostBack="true" OnSe...
  • wangjingjing1014
  • wangjingjing1014
  • 2015-03-02 15:15:29
  • 5399

asp.net中repeater嵌套CheckBoxList,RadioButtonList来完成投票

我们在做复式投票的时候。会遇到标题和选项嵌套的样子,下面我把我的代码放上来。1,投票选择前台页面 ...
  • chenguang79
  • chenguang79
  • 2008-07-04 14:49:00
  • 8208

repeater中CheckBoxList/RadioButtonList取值赋值

  • qq_27410185
  • qq_27410185
  • 2016-01-18 11:52:35
  • 238

repeater的使用方法详解

  大家可能都对datagrid比较熟悉,但是如果在数据量大的时候,我们就得考虑使用repeater作为我们的数据绑定控件了。Repeater控件与DataGrid (以及DataList)控件的主要...
  • jestar
  • jestar
  • 2008-07-29 11:39:00
  • 9378

RadioButtonList控件绑定数据时设定默认值

一般来说,我们对RadioButtonList控件绑定数据,已经熟练得无任何难度。但是如果有页面中,需要为RadioButtonList控件设定一个默认值为选中,或是把用户选择的选项已经存入数据库中,...
  • dyllove98
  • dyllove98
  • 2013-06-14 21:43:38
  • 3334

repeater嵌套repeater嵌套

  • 2010年10月21日 14:21
  • 9KB
  • 下载

Repeater嵌套RadioButtonList

select_web.aspx页:    选择题                                                                            ...
  • djk8888
  • djk8888
  • 2010-02-05 12:06:00
  • 544

RadioButtonList用法总结

这个控件可以做为判断来用,它还有事件响应机制,但要注意,若想应用其事件响应必须设置AutoPostBack="True".其事件响应能过OnSelectedIndexChanged="后台事件名称" ...
  • hui_shixu
  • hui_shixu
  • 2010-04-09 13:51:00
  • 3608

c# RadioButtonList默认第一个

TickStatus.Items.Add(new ListItem("所有")); this.TickStatus.SelectedIndex = 0;
  • yyattery
  • yyattery
  • 2015-08-05 11:33:47
  • 313
收藏助手
不良信息举报
您举报文章:repeater嵌套RadioButtonList
举报原因:
原因补充:

(最多只允许输入30个字)