前台代码:

<asp:GridView ID="GridView1" runat="server" DataKeyNames="ID" EmptyDataText="暂无试题" Width="100%" OnRowCommand="GridView1_RowCommand" AutoGenerateColumns="False">
                            <Columns>
                                <asp:TemplateField>
                                    <HeaderTemplate>
                                            <asp:Label id="Label24" runat="server" Text="一、单选题(每题1分)">
                                                    </asp:Label>
                                    </HeaderTemplate>
                                    <ItemTemplate>
                                        <table id="Table2" cellSpacing="1" cellPadding="1" width="100%" align="center" border="0">
                                            <tr>
                                                <td colSpan="4">
                                                    <asp:Label id="Label1" runat="server" Text='<%# Container.DataItemIndex+1 %>'>
                                                    </asp:Label>
                                                    <asp:Label id="Label2" runat="server" Text='<%# Eval("content","、{0}") %>'>
                                                    </asp:Label>
                                                    <asp:Label id="Label3" runat="server" Text='<%# Eval("answer") %>' Visible="False">
                                                    </asp:Label>
                                                    <asp:Label id="Label4" runat="server" Text='<%# Eval("ID") %>' Visible="False">
                                                    </asp:Label>
                                                    </td>
                                            </tr>
                                            <tr>
                                                <td width="35%">
                                                    <asp:RadioButton id="rbA" runat="server" Text='<%# Eval("answerA") %>' GroupName="Sl">
                                                    </asp:RadioButton></td>
                                                <td width="35%">
                                                    <asp:RadioButton id="rbB" runat="server" Text='<%# Eval("answerB") %>' GroupName="Sl">
                                                    </asp:RadioButton></td>
                                                <td></td>
                                            </tr>
                                            <tr>
                                                <td width="35%">
                                                    <asp:RadioButton id="rbC" runat="server" Text='<%# Eval("answerC") %>' GroupName="Sl">
                                                    </asp:RadioButton></td>
                                                <td width="35%">
                                                    <asp:RadioButton id="rbD" runat="server" Text='<%# Eval("answerD") %>' GroupName="Sl">
                                                    </asp:RadioButton></td>
                                                <td></td>
                                            </tr>
                                        </table>
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                            <HeaderStyle Font-Size="12pt" HorizontalAlign="Left" />
                        </asp:GridView>

后台代码:

遍历gridview的每一行,取得RadioButton的值。

 /// <summary>
    /// 提交按钮
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnCommit_Click(object sender, EventArgs e)
    {

        ItemOperater io = new ItemOperater(Session);

        ;//取出单选题的每题分值
        foreach (GridViewRow dr in GridView1.Rows)//对单选题每题进行判断用户选择答案
        {
            SelectedItem si = new SelectedItem();
            string str = "";
            if (((RadioButton)dr.FindControl("rbA")).Checked)
            {
                str = "A";

            }
            else if (((RadioButton)dr.FindControl("rbB")).Checked)
            {
                str = "B";
            }
            else if (((RadioButton)dr.FindControl("rbC")).Checked)
            {
                str = "C";
            }
            else if (((RadioButton)dr.FindControl("rbD")).Checked)
            {
                str = "D";
            }
            if (((Label)dr.FindControl("Label3")).Text.Trim() == str)//将用户选择结果和答案进行比较
            {
                score = score + singlemark;
            }
            si.selected = str; //选中的答案
            Label lbAnswer = (Label)dr.FindControl("Label3");
            Label lbID = (Label)dr.FindControl("Label4");
            si.answer = lbAnswer.Text.Trim();
            si.ID = Convert.ToInt32(lbID.Text.Trim());
            io.Add(si);
        }
        insert(io);  //加到数据库
        lbScore.Text = score+"";
    }
    public void insert(ItemOperater io) {
        ;
        if (Request["course_id"] != null)
        {
            course_id = Int32.Parse(Request["course_id"].ToString());
        }
        stu_id = Convert.ToInt32(Session["ID"].ToString());
        io.InsertScore(stu_id, score, course_id);
    }

gridView获得每行的值的更多相关文章

  1. ASP.NET 使用AJAX让GridView的数据行显示提示框(ToolTip)

    介绍ASP.NET AJAX可以使你的web应用程序具有更丰富的功能和更多的用户响应. 本文中,我将演示如何通过ASP.NET AJAX的帮助,给像GridView这样的数据绑定控件的数据行增加pop ...

  2. bash命令行返回值和展开

    bash命令行返回值和展开 标签(空格分隔): bash,命令,状态,展开 1.命令状态结果和执行结果 (1)命令执行的状态返回值,命令执行完成之后,其执行状态结果值保存于bash的特殊状态变量$?中 ...

  3. .net dataGridView当鼠标经过时当前行背景色变色;然后【给GridView增加单击行事件,并获取单击行的数据填充到页面中的控件中】

    1.首先在前台dataGridview属性中增加onRowDataBound属性事件 2.然后在后台Observing_RowDataBound事件中增加代码 protected void Obser ...

  4. 如何取得GridView被隐藏列的值

    如何取得GridView被隐藏列的值         分类:             ASP.net              2009-06-25 12:47     943人阅读     评论(1 ...

  5. DevExpress的GridView设置特定行的样式

    GridView控件绑定事件: gridView_SampleData.CustomDrawCell += gridView_SampleData_CustomDrawCell; 根据自定义逻辑来改变 ...

  6. JS弄ASP.NET(C#)在页GridView信息选择行

    做web发展还是新手我,为了之前获得Gridview中间值,它是通过服务器端控件通过第一Gridview将数据保存到服务器,当一个服务器,然后绑定的隐藏字段,在通过的js阅读隐藏字段值,如今,这种方法 ...

  7. GridView中数据行的操作

    一个是直接动态绑定gridview 用3楼的办法就可以了 int j=1;//j的数值表示你要取的那一列的索引,要取第二列,j就设为1for (int i = 0; i < this.GridV ...

  8. 转:GridView中RowDataBound的取值

    GridView是ASP.NET中功能强大的数据显示控件,它的RowDataBound事件为我们提供了方便的控制行.列数据的途径. 要获取当前行的某个数据列,我在实践中总结有如下几种方法: 1. Ce ...

  9. GridView点击行触发SelectedIndexChanged事件

    1.在<% @Page ...... %>指令中添加 EnableEventValidation="false" 2.在RowDataBound事件中添加 protec ...

随机推荐

  1. SQL Server 2014新特性——基数评估(白皮书阅读笔记)

    基数评估 目录 基数评估 说明 基数评估准确的重要性 模型假设 启用新的基数评估 验证基数评估的版本 在迁移到新的基数评估前要测试 校验基数评估 偏差问题 需要手动处理的变化 避免因为新的CE造成性能 ...

  2. 百度统计接口demo中错误

    百度统计接口中的demo(PHP版本)下载下来配置后运行出错,应该是编写demo时用的php版本比较低吧,作如下几处修改就好了 一:把CURLOPT_SSL_VERIFYHOST的值改为2,因为1版本 ...

  3. Mina架构与优化指南

    MINA架构 这里,我借用了一张Trustin Lee在Asia 2006的ppt里面的图片来介绍MINA的架构. Remote Peer就是客户端,而下方的框是MINA的主要结构,各个框之间的箭头代 ...

  4. JAVA 设计模式 迭代器模式

    用途 迭代器模式 (Iterator) 提供一种方法顺序访问一个聚合对象中各个元素,而又不暴露该对象的内部表示. 迭代器模式是一种行为型模式. 结构

  5. 基于caffe的艺术迁移学习 style-transfer-windows+caffe

    这个是在去年微博里面非常流行的,在git_hub上的代码是https://github.com/fzliu/style-transfer 比如这是梵高的画 这是你自己的照片 然后你想生成这样 怎么实现 ...

  6. 【Swift学习】Swift编程之旅---构造方法(十八)

    初始化是为了使用某个类.结构体或枚举类型的实例而进行的准备过程.这个过程包括为每个存储的属性设置一个初始值,然后执行新实例所需的任何其他设置或初始化.   初始化是通过定义构造器(Initialize ...

  7. Maven提高篇系列之(六)——编写自己的Plugin(本系列完)

    这是一个Maven提高篇的系列,包含有以下文章: Maven提高篇系列之(一)——多模块 vs 继承 Maven提高篇系列之(二)——配置Plugin到某个Phase(以Selenium集成测试为例) ...

  8. 扫描线 + 线段树 : 求矩形面积的并 ---- hnu : 12884 Area Coverage

    Area Coverage Time Limit: 10000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit user ...

  9. Ibatis中常见错误解决方案

    在Ibatis 的sqlMap或者sqlMapConfig配置文件中如果出现以下错误信息: Referenced file contains errors (http://www.ibatis.com ...

  10. 【书籍下载链接】_1_第一轮_C语言书籍

    各位朋友,如果您觉得下载的电子书,看的还可以,请购买纸质版的图书,如果您觉得 您下载的书,不值得一看请在下载后直接删除. Windows汇编:http://dl.vmall.com/c0jk1v970 ...