zoukankan      html  css  js  c++  java
  • asp grid 增加和删除行数据

    <table border="0" cellpadding="0" cellspacing="0" style=" 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=" 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="80">移除全部</a>
    </td>
    <td>
    <div style="height:200px;overflow-y:scroll;border:1px solid #808080;471px">
    已选人员:
    <asp:GridView ID="selectedGrid" runat="server" AutoGenerateColumns="False" style="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();
    }

  • 相关阅读:
    数组(Array)的使用方法
    Django中的事务操作
    什么是事务(Transaction)?事务的四个特性以及事务的隔离级别
    0.2 Django + Uwsgi + Nginx 的生产环境部署之实战篇
    0.1 Django + Uwsgi + Nginx 的生产环境部署之理论篇
    linux 进入编辑文件,保存退出相关命令
    Django--restframework
    使用用户名/邮箱/手机号 + 密码登陆 多形式登陆
    Django中异步任务---django-celery
    Redis 常用命令
  • 原文地址:https://www.cnblogs.com/zhang-wenbin/p/6364874.html
Copyright © 2011-2022 走看看