• 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();
    }

  • 相关阅读:
    QT内置的ICON资源
    Spark源代码阅读笔记之MetadataCleaner
    Android API Guides---Bluetooth
    做一个WINDOWS下破解WIFI。不须要Linux抓包!
    CPU GPU设计工作原理《转》
    杭电 1280 前m大的数
    机房收费系统——报表(2)
    概览C++之const
    Android动态禁用或开启屏幕旋转工具
    shrink-to-fit(自适应宽度)
  • 原文地址:https://www.cnblogs.com/zhang-wenbin/p/6364874.html
Copyright © 2020-2023  润新知