前台代码:

  1. <asp:GridView ID="GridView1" runat="server" DataKeyNames="ID" EmptyDataText="暂无试题" Width="100%" OnRowCommand="GridView1_RowCommand" AutoGenerateColumns="False">
  2. <Columns>
  3. <asp:TemplateField>
  4. <HeaderTemplate>
  5. <asp:Label id="Label24" runat="server" Text="一、单选题(每题1分)">
  6. </asp:Label>
  7. </HeaderTemplate>
  8. <ItemTemplate>
  9. <table id="Table2" cellSpacing="1" cellPadding="1" width="100%" align="center" border="0">
  10. <tr>
  11. <td colSpan="4">
  12. <asp:Label id="Label1" runat="server" Text='<%# Container.DataItemIndex+1 %>'>
  13. </asp:Label>
  14. <asp:Label id="Label2" runat="server" Text='<%# Eval("content","、{0}") %>'>
  15. </asp:Label>
  16. <asp:Label id="Label3" runat="server" Text='<%# Eval("answer") %>' Visible="False">
  17. </asp:Label>
  18. <asp:Label id="Label4" runat="server" Text='<%# Eval("ID") %>' Visible="False">
  19. </asp:Label>
  20. </td>
  21. </tr>
  22. <tr>
  23. <td width="35%">
  24. <asp:RadioButton id="rbA" runat="server" Text='<%# Eval("answerA") %>' GroupName="Sl">
  25. </asp:RadioButton></td>
  26. <td width="35%">
  27. <asp:RadioButton id="rbB" runat="server" Text='<%# Eval("answerB") %>' GroupName="Sl">
  28. </asp:RadioButton></td>
  29. <td></td>
  30. </tr>
  31. <tr>
  32. <td width="35%">
  33. <asp:RadioButton id="rbC" runat="server" Text='<%# Eval("answerC") %>' GroupName="Sl">
  34. </asp:RadioButton></td>
  35. <td width="35%">
  36. <asp:RadioButton id="rbD" runat="server" Text='<%# Eval("answerD") %>' GroupName="Sl">
  37. </asp:RadioButton></td>
  38. <td></td>
  39. </tr>
  40. </table>
  41. </ItemTemplate>
  42. </asp:TemplateField>
  43. </Columns>
  44. <HeaderStyle Font-Size="12pt" HorizontalAlign="Left" />
  45. </asp:GridView>

后台代码:

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

  1. /// <summary>
  2. /// 提交按钮
  3. /// </summary>
  4. /// <param name="sender"></param>
  5. /// <param name="e"></param>
  6. protected void btnCommit_Click(object sender, EventArgs e)
  7. {
  8.  
  9. ItemOperater io = new ItemOperater(Session);
  10.  
  11. ;//取出单选题的每题分值
  12. foreach (GridViewRow dr in GridView1.Rows)//对单选题每题进行判断用户选择答案
  13. {
  14. SelectedItem si = new SelectedItem();
  15. string str = "";
  16. if (((RadioButton)dr.FindControl("rbA")).Checked)
  17. {
  18. str = "A";
  19.  
  20. }
  21. else if (((RadioButton)dr.FindControl("rbB")).Checked)
  22. {
  23. str = "B";
  24. }
  25. else if (((RadioButton)dr.FindControl("rbC")).Checked)
  26. {
  27. str = "C";
  28. }
  29. else if (((RadioButton)dr.FindControl("rbD")).Checked)
  30. {
  31. str = "D";
  32. }
  33. if (((Label)dr.FindControl("Label3")).Text.Trim() == str)//将用户选择结果和答案进行比较
  34. {
  35. score = score + singlemark;
  36. }
  37. si.selected = str; //选中的答案
  38. Label lbAnswer = (Label)dr.FindControl("Label3");
  39. Label lbID = (Label)dr.FindControl("Label4");
  40. si.answer = lbAnswer.Text.Trim();
  41. si.ID = Convert.ToInt32(lbID.Text.Trim());
  42. io.Add(si);
  43. }
  44. insert(io); //加到数据库
  45. lbScore.Text = score+"";
  46. }
  47. public void insert(ItemOperater io) {
  48. ;
  49. if (Request["course_id"] != null)
  50. {
  51. course_id = Int32.Parse(Request["course_id"].ToString());
  52. }
  53. stu_id = Convert.ToInt32(Session["ID"].ToString());
  54. io.InsertScore(stu_id, score, course_id);
  55. }

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. Windows Azure Cloud Service (12) PaaS之Web Role, Worker Role, Azure Storage Queue(下)

    <Windows Azure Platform 系列文章目录> 本章DEMO部分源代码,请在这里下载. 在上一章中,笔者介绍了我们可以使用Azure PaaS的Web Role和Worke ...

  2. 【Pig源码分析】谈谈Pig的数据模型

    1. 数据模型 Schema Pig Latin表达式操作的是relation,FILTER.FOREACH.GROUP.SPLIT等关系操作符所操作的relation就是bag,bag为tuple的 ...

  3. 【Swift学习】Swift编程之旅---函数(十)

    函数是一组用于执行特定任务的独立的代码段,你用一个名字来标识函数,这个名字是用来“调用”函数来执行它的任务. swift统一函数的语法具有足够的灵活性来表达任何一个简单的不带参数的名称与本地和外部的每 ...

  4. 相同版本的CDH集群间迁移hdfs以及hbase

    前言 由于项目数据安全的需要,这段时间看了下hadoop的distcp的命令使用,不断的纠结的问度娘,度娘告诉我的结果也让我很纠结,都是抄来抄去, 还好在牺牲大量的时间的基础上还终于搞出来了,顺便写这 ...

  5. MVC的路径查找顺序

    使用MVC的朋友们,知道MVC的funny之处. 但是如果出现路径找不到,请记住以下的页面路径寻找顺序. http://www.cnblogs.com/sosoft/ 首先,知道你的Controlle ...

  6. 解决android sdk 无法更新

    今天更新sdk,遇到了更新下载失败问题: Fetching https://dl-ssl.google.com/android/repository/addons_list-2.xmlFetched ...

  7. 修复一个吉日嘎拉MSSQL数据库版中的分页存储过程bug

    这个存储过程是3.7以来一直存在,并未针对MSSQL2005以上版本进行ROW_NUMBER() OVER升级,还是延续TOP的写法.这并非是我所谓的bug,我所说的bug是指执行了排序的字段,如果字 ...

  8. 【Java每日一题】20161103

    package Nov2016; import java.util.List; public class Ques1103 { public void method01(String[] array) ...

  9. Flume

    http://www.ibm.com/developerworks/cn/data/library/bd-1404flumerevolution/index.html https://flume.ap ...

  10. CSS选择器(一)

    CSS选择器包括标签选择器.ID选择器.类选择器.伪类和伪对象选择器.子选择器.相邻选择器.属性选择器.通用选择器.包含选择器.分组选择器.指定选择器等选择器,分为标签选择器.ID选择器.类选择器.特 ...