<table border="0" cellpadding="0" cellspacing="0" style="width: 100%; Height: 170px">
<tr>
<td>
<table>
<tr>
<td>请选择参加考人员:</td>
</tr>
<tr>
<td>
<div style="height: 200px; overflow-y: scroll">
<asp:GridView ID="EmployeeGrid" runat="server" AutoGenerateColumns="False" Style="height: 170px" AllowPaging="True" PageSize="1000">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="WorkNumber" HeaderText="工号" SortExpression="WorkNumber" />
<asp:BoundField DataField="EmployeeName" HeaderText="姓名" />
<asp:BoundField DataField="ChineseName" HeaderText="岗位" />
<asp:BoundField DataField="JobName" HeaderText="部门" />
</Columns>
</asp:GridView>
</div>
</td>
<td style="width: 120px">
<asp:Button Text=" ==> " runat="server" ID="addWorker" OnClick="addWorker_Click" BorderStyle="None" /><br />
<br />
<asp:Button Text=" <== " runat="server" ID="deleteWorker" BorderStyle="None" OnClick="deleteWorker_Click" /><br />
<br />
<a id="removeAll" href="javascript:void(0);" class="easyui-linkbutton" data-options="width:80">移除全部</a>
</td>
<td>
<div style="height:200px;overflow-y:scroll;border:1px solid #808080;width:471px">
已选人员:
<asp:GridView ID="selectedGrid" runat="server" AutoGenerateColumns="False" style="width:450px;" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="WorkNumber" HeaderText="工号" SortExpression="WorkNumber" />
<asp:BoundField DataField="EmployeeName" HeaderText="姓名" />
<asp:BoundField DataField="ChineseName" HeaderText="岗位" />
<asp:BoundField DataField="JobName" HeaderText="部门" />
</Columns>
</asp:GridView></div>
</td>
</tr>
</table>
</td>
</tr>
</table>

protected void addWorker_Click(object sender, EventArgs e)
{
DataTable table = new DataTable();
table.Columns.Add(new DataColumn("WorkNumber"));
table.Columns.Add(new DataColumn("EmployeeName"));
table.Columns.Add(new DataColumn("ChineseName"));
table.Columns.Add(new DataColumn("JobName"));
foreach (GridViewRow row in selectedGrid.Rows)
{
DataRow sourseRow = table.NewRow();
sourseRow["WorkNumber"] = row.Cells[1].Text;
sourseRow["EmployeeName"] = row.Cells[2].Text;
sourseRow["ChineseName"] = row.Cells[3].Text;
sourseRow["JobName"] = row.Cells[4].Text;
table.Rows.Add(sourseRow);
}
int rowCount = this.EmployeeGrid.Rows.Count;
for (int i = 0; i < rowCount; i++)
{
CheckBox tempChk = (CheckBox)EmployeeGrid.Rows[i].FindControl("CheckBox1");
if (tempChk.Checked == true)
{
DataRow sourseRow = table.NewRow();
sourseRow["WorkNumber"] = EmployeeGrid.Rows[i].Cells[1].Text;
sourseRow["EmployeeName"] = EmployeeGrid.Rows[i].Cells[2].Text;
sourseRow["ChineseName"] = EmployeeGrid.Rows[i].Cells[3].Text;
sourseRow["JobName"] = EmployeeGrid.Rows[i].Cells[4].Text;
table.Rows.Add(sourseRow);
((CheckBox)EmployeeGrid.Rows[i].FindControl("CheckBox1")).Checked=false;
}
}
this.selectedGrid.DataSource = table;
this.selectedGrid.DataBind();
}
protected void deleteWorker_Click(object sender, EventArgs e)
{
DataTable table = new DataTable();
table.Columns.Add(new DataColumn("WorkNumber"));
table.Columns.Add(new DataColumn("EmployeeName"));
table.Columns.Add(new DataColumn("ChineseName"));
table.Columns.Add(new DataColumn("JobName"));
foreach (GridViewRow row in selectedGrid.Rows)
{
DataRow sourseRow = table.NewRow();
sourseRow["WorkNumber"] = row.Cells[1].Text;
sourseRow["EmployeeName"] = row.Cells[2].Text;
sourseRow["ChineseName"] = row.Cells[3].Text;
sourseRow["JobName"] = row.Cells[4].Text;
table.Rows.Add(sourseRow);
}
foreach (GridViewRow row in selectedGrid.Rows)
{
if (((CheckBox)row.Cells[0].FindControl("CheckBox1")).Checked)
{
foreach (DataRow dtRow in table.Rows)
{
if (dtRow["WorkNumber"].ToString() == row.Cells[1].Text)
{
table.Rows.Remove(dtRow);
break;
}
}
}
}
selectedGrid.DataSource = table;
selectedGrid.DataBind();
}

asp grid 增加和删除行数据的更多相关文章

  1. asp.net mvc3 linq实现数据的增、删、改、查、

    asp.net mvc 3 linq实现数据的增.删.改.查. 添加数据 定义一个对象: public class Student { public int id{get; set;} public ...

  2. JQuery实现表格的增加行和删除行

    利用JQuery实现datatables插件的增加和删除行操作 在学习过程中遇到了这个利用JQuery对表格行的增加和删除,特记录下来以供初学者参考. 下面是主要的代码: <meta http- ...

  3. ASP.NET MVC 5 - 将数据从控制器传递给视图

    在我们讨论数据库和数据模型之前,让我们先讨论一下如何将数据从控制器传递给视图.控制器类将响应请求来的URL.控制器类是给您写代码来处理传入请求的地方,并从数据库中检索数据,并最终决定什么类型的返回结果 ...

  4. ASP图片格式与base64数据互转方法

    ASP图片格式与base64数据相互转换的方法,经常用于处理表单中存储有base64字符串格式的图片. 获取到base64数据,转换成图片 <% Subfolder=year(now)& ...

  5. 【ASP.NET MVC系列】数据验证和注解

    [01]浅谈Google Chrome浏览器(理论篇) [02]浅谈Google Chrome浏览器(操作篇)(上) [03]浅谈Google Chrome浏览器(操作篇)(下) [04]浅谈ASP. ...

  6. 我用ASP.NET缓存之SQL数据缓存依赖(SqlCacheDependency)

    [名词解释] 缓存(Cache)依赖,大白话解释就是缓存是否更新依赖于其它Object.那么SqlCacheDependency指的就是Cache的数据更新依赖于SQL Server数据库表的变化(  ...

  7. [转]ASP.NET MVC 5 - 将数据从控制器传递给视图

    在我们讨论数据库和数据模型之前,让我们先讨论一下如何将数据从控制器传递给视图.控制器类将响应请求来的URL.控制器类是给您写代码来处理传入请求的地方,并从数据库中检索数据,并最终决定什么类型的返回结果 ...

  8. ASP.NET网页动态添加数据行

    一看到这标题<ASP.NET网页动态添加数据行>,想起来似乎有点难实现.因为网页的周期性原因,往往在PostBack之后,状态难于有所保留.但Insus.NET又想实现这样的效果,用户点击 ...

  9. ASP.NET Core Identity 迁移数据 - ASP.NET Core 基础教程 - 简单教程,简单编程

    原文:ASP.NET Core Identity 迁移数据 - ASP.NET Core 基础教程 - 简单教程,简单编程 ASP.NET Core Identity 迁移数据 上一章节中我们配置了 ...

随机推荐

  1. python学习第6天

    id is ==  代码块 代码块的缓存机制 小数据池(不同代码块的缓存机制) 小数据池(驻留机制)总结 数据类型之间的转换 int bool str 三者转化是可以的. bool 可以与所有的数据类 ...

  2. REST风格接口测试利器Wisdom rest-client

    前言 偶然间接触到Wisdom rest-client这款测试工具,后来经过尝试体验,感觉还不错,现在分享给大家,如何使用这款测试利器 Wisdom rest-client是什么? Wisdom re ...

  3. PHP字符串比较,看起来值完全一样,但是就是不相等的解决方案(&zwnj;)

    1 前言 字符串比较,看起来完全一样,然后用strcmp比较,永远不相等,用var_dump查看才知道,其中一个字符多了‌看不见的特殊符号,而我长度是3. 2 样例 当你选中它,显示出来的就是人眼所见 ...

  4. SpringBoot和SpringCloud面试题

    一. 什么是springboot 1.用来简化spring应用的初始搭建以及开发过程 使用特定的方式来进行配置(properties或yml文件) 2.创建独立的spring引用程序 main方法运行 ...

  5. 执行原生SQL语句的方式

    原生sql语句 cursor方法:from api.models import *from django.db import connection,connectionscursor=connecti ...

  6. Codeforces 1114F Please, another Queries on Array? [线段树,欧拉函数]

    Codeforces 洛谷:咕咕咕 CF少有的大数据结构题. 思路 考虑一些欧拉函数的性质: \[ \varphi(p)=p-1\\ \varphi(p^k)=p^{k-1}\times (p-1)= ...

  7. c# 图片插入Excel

    引用COM:Microsoft Office 11.0 Object Library 引用类:    using System;    using System.Windows.Forms;    u ...

  8. GZip使用

    class Program { static void Main(string[] args) { //Trace.Listeners.Clear(); //Trace.Listeners.Add(n ...

  9. Windows 系统共享文件扫描

    近年来历次泄露的安全事故(工控安全),其主要原因就是内部网络自身的脆弱性问题.对于内部网络的安全检查是很必要的.传统上使用CMD命令  net view 就可以扫描在线的主机但是,主机设置取消QOS的 ...

  10. HTML&javaSkcript&CSS&jQuery&ajax(二)

    一.HTML 1.标签<a href="http:www.baidu.com">This is a link </a>         <img sr ...