asp gridview
<table>
                                <tr>
                                    <td colspan="5">请选择试卷制定人员<span style="color:red">(选一人即可)</span>:</td>
                                </tr>
                                <tr>
                                    <td style="width:50px;">姓名:</td>
                                    <td style="width:80px;"><asp:TextBox ID="txtemployee" runat="server" Width="80px" ></asp:TextBox></td>
                                    <td style="width:50px;">部门:</td>
                                    <td style="width:120px;"><asp:TextBox ID="txtdepartment" runat="server" Width="120px" ></asp:TextBox></td>
                                    <td style="text-align:left"><asp:Button ID="btnquery" runat="server" Text="查询" Width="80px" OnClick="btnquery_Click" /></td>
                                </tr>
                                <tr>
                                    <td colspan="5">
                                        <div style="height: 200px; overflow-y: scroll;width:500px;border:1px solid #808080;">
                                            <asp:GridView ID="EmployeeGrid" runat="server" AutoGenerateColumns="False" Width="480px" BorderColor="#ffffff" BorderStyle="None" BorderWidth="0px" >
                                                <Columns>
                                                    <asp:TemplateField>
                                                        <ItemTemplate>
                                                            <asp:CheckBox ID="CheckBox1" runat="server" />
                                                        </ItemTemplate>
                                                    </asp:TemplateField>
                                                    <asp:BoundField DataField="WorkNumber" HeaderText="工号" HeaderStyle-HorizontalAlign="Left" SortExpression="WorkNumber" />
                                                    <asp:BoundField DataField="EmployeeName" HeaderText="姓名" HeaderStyle-HorizontalAlign="Left" />
                                                    <asp:BoundField DataField="ChineseName" HeaderText="部门" HeaderStyle-HorizontalAlign="Left" />
                                                    <asp:BoundField DataField="JobName" HeaderStyle-Width="130px" HeaderText="岗位" HeaderStyle-HorizontalAlign="Left" />
                                                </Columns>
                                            </asp:GridView>
                                        </div>
                                    </td>
                                    <td style="width: 120px;padding-left:50px">
                                        <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 />
                                    </td>
                                    <td>
                                        <div style="height:200px;overflow-y:scroll;border:1px solid #808080;width:500px">
                                            已选人员:
                                        <asp:GridView ID="selectedGrid" runat="server" AutoGenerateColumns="False" style="width:480px;" BorderColor="#ffffff" >
                                            <Columns>
                                                <asp:TemplateField>
                                                    <ItemTemplate>
                                                        <asp:CheckBox ID="CheckBox1" runat="server" />
                                                    </ItemTemplate>
                                                </asp:TemplateField>
                                                <asp:BoundField DataField="WorkNumber" HeaderText="工号" SortExpression="WorkNumber" HeaderStyle-HorizontalAlign="Left" />
                                                <asp:BoundField DataField="EmployeeName" HeaderText="姓名"  HeaderStyle-HorizontalAlign="Left" />
                                                <asp:BoundField DataField="ChineseName" HeaderText="部门" HeaderStyle-HorizontalAlign="Left" />
                                                <asp:BoundField DataField="JobName" HeaderStyle-Width="130px" HeaderText="岗位" HeaderStyle-HorizontalAlign="Left"  />
                                            </Columns>
                                        </asp:GridView></div>
                                    </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;
                break;
            }
        }
        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();
    }
    //初始化员工信息
    public void InitWorkers(string workername, string department)
    {
        SqlConnection Conn = new SqlConnection(ConfigurationManager.ConnectionStrings["LogInConnectionString"].ConnectionString);
        Conn.Open();
        string strSQL = "select * from (";
        strSQL += "select ROW_NUMBER() over(order by EmployeeName) as xuhao, e.WorkNumber,e.EmployeeName,p.ChineseName,j.JobName from PUB_Employee e join ";
        strSQL += " PUB_FrameworkRelation f on f.RelationID=e.EmployeeCode ";
        strSQL += " join PUB_Post p on p.ID=e.PostID ";
        strSQL += " join PUB_Job j on j.ID=e.JobID ";
        strSQL += " where f.CancelState=0 ";
        strSQL += " ) source where 1=1 ";
        if (!string.IsNullOrEmpty(workername))
        {
            strSQL += " and source.EmployeeName like '%" + workername + "%'";
        }
        if (!string.IsNullOrEmpty(department))
        {
            strSQL += " and source.ChineseName like '%" + department + "%'";
        }
        SqlDataAdapter da = new SqlDataAdapter(strSQL.ToString(), Conn);
        //实例化 DataSet 数据集 这个数据集会绑定在gridview上
        DataSet data = new DataSet();
        //向数据集中fill(填入)数据 da填入data
        da.Fill(data, "table");
        //将填好数据的数据集data 绑定到gridView空间上
        this.EmployeeGrid.DataSource = data;
        this.EmployeeGrid.DataBind();
    }
    protected void btnquery_Click(object sender, EventArgs e)
    {
        InitWorkers(txtemployee.Text, txtdepartment.Text);
    }
asp gridview的更多相关文章
- asp gridview批量删除和全选
		本人新手刚学asp.net 全选和删除也是引用了他人的代码试了一试可以实现,感觉很好,就发了上来. 前台代码 <asp:GridView ID="GridView1" r ... 
- asp:ObjectDataSource+asp:GridView 实现真分页
		<asp:GridView ID="GridViewCacheManager" DataSourceID="OdsCacheManager" runat= ... 
- asp:GridView控件的使用
		使用asp:GridView显示一个统计的表格 cs样式: <style> table.gridview_m { border-colla ... 
- asp  Gridview绑定形式获取行号
		Gridview中使用<%# Container.DataItemIndex %>取得当前行的序号 而在Repeater控件中使用Container.ItemIndex取得当前行的序号 & ... 
- asp:gridview 中显示日期格式
		boundfield中应该这样设置: <asp:BoundField HeaderText="发表时间" DataField="PostTime" Htm ... 
- asp:GridView控件使用FindControl方法获取控件的问题
		一.使用带cells的指定列 e.Item.Cells[1].Controls[1]只指定第二列的第二个控件 二.不使用带cells的指定类e.Item.FindControl("ID&qu ... 
- Asp.Net 操作XML文件的增删改查 利用GridView
		不废话,直接上如何利用Asp.NET操作XML文件,并对其属性进行修改,刚开始的时候,是打算使用JS来控制生成XML文件的,但是最后却是无法创建文件,读取文件则没有使用了 index.aspx 文件 ... 
- asp.net(C#)读取文件夹和子文件夹下所有文件,绑定到GRIDVIEW并排序 .
		Asp部分: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MyFiles ... 
- Asp.net中导出Excel文档(Gridview)
		主要思路,通过GridView来导出文档. 新建一个Aspx页面,页面创建GridView控件,后台绑定好数据源.然后load中直接打印即可导出 前台的GridView <asp:GridVie ... 
随机推荐
- SQL Server 之 内部连接
			1.内部联接 2.外部联接 外部联接扩展了内部联接的功能,会把内联接中删除表源中的一些保留下来,由于保存下来的行不同,可将外部联接分为左联接和右联接. 2.1左联接: 如果左表的某一行在右表中没有匹配 ... 
- python  old six day
			今天主要内容: . is 和== 的区别 . 编程的问题 一. is和==的区别! is 比较的是内存地址 == 比较的是值 记住结果就好 ⑴id 通过id() 我们查看到一个变量表示 ... 
- Ex 2_5 求解递推式..._第三次作业
- 【原创】大数据基础之Logstash(1)简介、安装、使用
			Logstash 6.6.2 官方:https://www.elastic.co/products/logstash 一 简介 Centralize, Transform & Stash Yo ... 
- ios中input获取焦点时的问题
			1.获取焦点时,input会变大 解决办法是:font-size设置为32px以上 还有就是要在header里面加这一行代码:<meta name="viewport" co ... 
- linux命令知识点
			1. 例二:列出当前目录中所有以“t”开头的目录的详细内容,可以使用如下命令: 命令:ls -l t* 例六:计算当前目录下的文件数和目录数 命令: ls -l * |grep "^-&qu ... 
- python   列表,字典,元组,字符串,常用函数
			飞机票 一.列表方法 1.ls.extend(object) 向列表ls中插入object中的每个元素,object可以是字符串,元组和列表(字符串“abc”中包含3个元组),相当于ls和object ... 
- Socket通讯成功案例
			Socket通讯案例 #region 服务端 //int port = 1234; //string host = "127.0.0.1"; //IPAddress ip = IP ... 
- Redis扩展
			Redis扩展下载地址:https://windows.php.net/downloads/pecl/releases/redis/ PHP怎么安装redis扩展 http://www.php.cn/ ... 
- C++ Primer 笔记——类成员指针
			1.当我们初始化一个成员指针或为成员指针赋值时,该指针并没有指向任何数据.成员指针指定了成员而非成员所属的对象,只有当解引用成员指针时,我们才提供对象信息. 2.和普通的函数指针类似,如果成员存在重载 ... 
