当前位置: 首页 > news >正文

在asp.net中如何获取asp:DataList中子控件asp:RadioButtonList的值

前台:

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

<!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>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DataList ID="DataList1_TMB_TestQuestion" runat="server" BackColor="White"
            BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3"
            GridLines="Both">
            <FooterStyle BackColor="White" ForeColor="#000066" />
            <ItemStyle ForeColor="#000066" />
            <SelectedItemStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
            <ItemTemplate>
                <table>
                    <tr>
                        <td><asp:Label ID="Label2" runat="server" Text=<%# ((System.Data.DataRowView)Container.DataItem).Row["FTQID"].ToString().Substring(7, 3)%>></asp:Label>、</td>
                       

                        <td><asp:Label ID="Label1" runat="server" Text=<%# Eval("FTQName") %> ></asp:Label></td>
                    </tr>
                    <tr>
                        <td></td>
                        <td><asp:RadioButtonList ID="RadioButtonList1" runat="server" Font-Size="9pt" RepeatDirection="Horizontal">
                                <asp:ListItem Value="0">从无</asp:ListItem>
                                <asp:ListItem Value="1">轻度</asp:ListItem>
                                <asp:ListItem Value="2">中度</asp:ListItem>
                                <asp:ListItem Value="3">偏重</asp:ListItem>
                                <asp:ListItem Value="4">严重</asp:ListItem>
                            </asp:RadioButtonList></td>
                    </tr>
                </table>
            </ItemTemplate>
        </asp:DataList>
        <asp:Button ID="Button1" runat="server" Text="交卷" οnclick="Button1_Click" />
    </div>
    </form>
</body>
</html>

后台:

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

using System.Data.SqlClient;
public partial class search_zhengzhuang : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DataBind();
        }
    }

    public void DataBind()
    {
        string strProvider = ConfigurationManager.ConnectionStrings["PhysiqueCheckConnectionString"].ConnectionString;
        SqlConnection MyConn = new SqlConnection(strProvider);

        MyConn.Open();

        DataSet dataSet = new DataSet();
        SqlDataAdapter adapter = new SqlDataAdapter(" select TMB_TestQuestion.* from TMB_TestQuestion where TMB_TestQuestion.FTQID like '000001%'", MyConn);

        adapter.Fill(dataSet, "TMB_TestQuestion");

        DataList1_TMB_TestQuestion.DataSource = dataSet;
        DataList1_TMB_TestQuestion.DataBind();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string strProvider = ConfigurationManager.ConnectionStrings["PhysiqueCheckConnectionString"].ConnectionString;
        SqlConnection MyConn = new SqlConnection(strProvider);
        MyConn.Open();

        string strSel = "delete TMG_Result where FIndex='0009'";
        SqlCommand cmd = new SqlCommand(strSel, MyConn);
        SqlDataReader reader = cmd.ExecuteReader();
        reader.Dispose();

        //SqlCommand cmd = new SqlCommand();
        //cmd.Connection = MyConn;
        //SqlDataReader reader = null;
        string getvalue=null;    
       for(int i=0;i <this.DataList1_TMB_TestQuestion.Items.Count;i++)
       {

           getvalue = ((RadioButtonList)this.DataList1_TMB_TestQuestion.Items[i].FindControl("RadioButtonList1")).SelectedValue.ToString();   //重要的是这句话
           if (getvalue == null || getvalue.Equals(""))
           {
              
               Response.Write("<script>alert('第" + (i+1) + "题未填!')</script>");
               break;
           }


           strSel = "insert into TMG_Result(FRecord,FOrder,FQuesID,FItemID,FIndex,FExported) values("+i+","+i+","+i+"," + getvalue + ",0009,3)";
           cmd.CommandText = strSel;
           reader = cmd.ExecuteReader();
           reader.Dispose();
       }
    }


}

转载于:https://www.cnblogs.com/carekee/articles/2094817.html

相关文章:

  • Laputa在cnblogs
  • sk_buff封装和解封装网络数据包的过程详解
  • android 调用系统摄像头
  • _shared_pool_reserved_pct or shared_pool_reserved_size with ASMM
  • jQuery选择器详解[转]
  • linux 下安装tomcat
  • 上传表单的样式模拟
  • CentOS 6.8无法启动图形界面
  • django login 限制
  • qmail 邮件过滤与抄送
  • 域控安装问题集锦
  • GPS开发报错provider为空问题解决
  • 使用序列化快速读写XML文件
  • rsync 配置说明和命令参数
  • 宏常用例子
  • 08.Android之View事件问题
  • CAP 一致性协议及应用解析
  • CSS实用技巧
  • css系列之关于字体的事
  • FineReport中如何实现自动滚屏效果
  • go append函数以及写入
  • in typeof instanceof ===这些运算符有什么作用
  • jQuery(一)
  • markdown编辑器简评
  • miaov-React 最佳入门
  • Nginx 通过 Lua + Redis 实现动态封禁 IP
  • Promise面试题2实现异步串行执行
  • React-redux的原理以及使用
  • SAP云平台运行环境Cloud Foundry和Neo的区别
  • SpiderData 2019年2月23日 DApp数据排行榜
  • TypeScript实现数据结构(一)栈,队列,链表
  • vue2.0开发聊天程序(四) 完整体验一次Vue开发(下)
  • 包装类对象
  • 编写高质量JavaScript代码之并发
  • 测试如何在敏捷团队中工作?
  • - 概述 - 《设计模式(极简c++版)》
  • 离散点最小(凸)包围边界查找
  • 你真的知道 == 和 equals 的区别吗?
  • 算法-图和图算法
  • 这几个编码小技巧将令你 PHP 代码更加简洁
  • ​业务双活的数据切换思路设计(下)
  • # include “ “ 和 # include < >两者的区别
  • (cljs/run-at (JSVM. :browser) 搭建刚好可用的开发环境!)
  • (二)windows配置JDK环境
  • (附源码)springboot建达集团公司平台 毕业设计 141538
  • (附源码)计算机毕业设计高校学生选课系统
  • (全部习题答案)研究生英语读写教程基础级教师用书PDF|| 研究生英语读写教程提高级教师用书PDF
  • (完整代码)R语言中利用SVM-RFE机器学习算法筛选关键因子
  • (转)fock函数详解
  • (总结)Linux下的暴力密码在线破解工具Hydra详解
  • .md即markdown文件的基本常用编写语法
  • .NET / MSBuild 扩展编译时什么时候用 BeforeTargets / AfterTargets 什么时候用 DependsOnTargets?
  • .NET Core实战项目之CMS 第十二章 开发篇-Dapper封装CURD及仓储代码生成器实现
  • .NET/C# 如何获取当前进程的 CPU 和内存占用?如何获取全局 CPU 和内存占用?
  • .NET开源项目介绍及资源推荐:数据持久层