<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. git的简单使用(windows)

    使用参考文档 git简易指南:http://www.bootcss.com/p/git-guide/ git官方文档:https://git-scm.com/book/zh/v1/%E8%B5%B7% ...

  2. Windows上的程序员神器Cmder

    用过Windows版本Git的都知道Git自带了Git Bash,这个在很大程度上满足了我的需求,随着Git的版本升级越来越好用 安装Cmder Cmder官网,它把conemu,msysgit和cl ...

  3. webStorm 快捷键 + 浏览器

    webStorm 快捷键 shift + enter  不管光标在哪个位置 新建一行 Ctrl + G          查找行Ctrl + B          查找函数Ctrl + D      ...

  4. Cropper.js使用笔记

    官网:https://fengyuanchen.github.io/cropperjs/ github:https://github.com/fengyuanchen/cropperjs 由于文档不好 ...

  5. CSS学习——基础分类整理

        1. CSS     层叠样式表: Cascading Style Sheets,定义如何显示html元素 CSS规则: 选择器{属性: 值; 属性: 值;} CSS注释: /*在这里写注释说 ...

  6. web页面乱码,JSP页面编码设置

    解决Web页面访问出现乱码bug,JSP页面首行添加: <%@ page language="java" contentType="text/html; chars ...

  7. Confluence 6 WebDAV 禁用严格路径检查

    如果你在你的 WebDAV 客户端发现了一些不正常的现象,例如文件夹在 Confluence 中是存在的,但是在你客户端下载的文件中就不存在了.你可以禁用  WebDAV 插件中的严格路径检查选项,这 ...

  8. ionic3 调用摄像头 当键盘弹出时候 出现摄像头 背景

    iOS 端毫无 bug,Android 端却出现了问题.当软键盘弹出后,Android 端的 tabs 移到了软键盘的上面,再仔细一看,整个界面都被压扁了,输入框也不知道去哪儿了. 于是去翻 Ioni ...

  9. linux符号与正则表达式

    特殊符号    >    或者1>   标准输出重定向 先把文件的内容清空  再放入新的内容 >> 或   2>>  追加重定向  把内容放入文件的最后一行 1   ...

  10. Python全栈习题一

    1.执行 Python 脚本的两种方式 a../run.py  直接在命令行调用python脚本: b.python run.py 调用python解释器来调用Python脚本. 2.简述位.字节的关 ...