<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. C# 后台请求api

    /// <summary> /// 指定Post地址使用Get 方式获取全部字符串 /// </summary> /// <param name="url&qu ...

  2. PHP中$_POST和$_GET的用法

    post和get是指:页面提交的两种方式get:参数都体现在url上,可以用于翻页,简单查询,get只能接收2M以下的内容,所以有局限性,另外由于内容是可见的,安全性就下降了,post:用于页面表单 ...

  3. 《深入理解Oracle 12c数据库管理(第二版)》PDF

    一:下载获取位置: 二:本书图样: 三:本书目录: 图书目录: 第1章 安装Oracle 1.1 了解OFA 1.1.1 Oracle清单目录 1.1.2 Oracle基础目录 1.1.3 Oracl ...

  4. Android 自动化测试框架

    Android常用的自动化测试工具框架: Monkey,MonkeyRunner,UIAutomator,Robotium,Appium,Monkey Talk...... 但这些工具框架都是什么呢有 ...

  5. vuex action 与mutations 的区别

    面试没说清楚.这个太丢人回来整理下: 事实上在 vuex 里面 actions 只是一个架构性的概念,并不是必须的,说到底只是一个函数,你在里面想干嘛都可以,只要最后触发 mutation 就行.异步 ...

  6. 基于Form组件实现的增删改和基于ModelForm实现的增删改

    一.ModelForm的介绍 ModelForm a. class Meta: model, # 对应Model的 fields=None, # 字段 exclude=None, # 排除字段 lab ...

  7. Python使用re模块实现正则表达式操作

    Python提供了re模块,用于实现正则表达式的操作.在实现时,可以使用re模块提供的方法(如search().match().findall()等)进行字符串处理,也可以先使用re模块的compil ...

  8. spring-data-mongo的MongoTemplate开发

    spring-data-mongo的MongoTemplate开发 1.在实体类Customer.Java中引入注解表明转换方式 @Document   //文档 public class Custo ...

  9. jmeter 中如何一次运行多条sql语句

    在jmeter测试mysql中如何一次运行多条sql语句 allowMultiQueries=true 注意:太低版本的mysql和jdbc不支持,最好用最新版的

  10. 繁简字转换(C#)

    1.首先引入: using Microsoft.VisualBasic; 2.转换方法: //繁体转简体 public static string Traditional2Simplified(str ...