GridView …删查改 分页 自定义分页搜索 完整版

 

 

.cs 页面

public partial class ProjectSeven_HRSpecial : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindGridView();
        }
    }
 
    protected void BindGridView()
    {
        string strSql = "select * from HRSPECIAL_Repair where 0=0";
        if (!string.IsNullOrEmpty(this.txtDept.Text.Trim()))
        {
            strSql += "and DEPT_NAME like '" + this.txtDept.Text.Trim() + "'";
        }
        if (!string.IsNullOrEmpty(this.HidDept.Value.Trim()))
        {
            strSql += "and DEPT like '" + this.HidDept.Value.Trim() + "' ";
        }
 
        if (!string.IsNullOrEmpty(this.txtHrbp.Text.Trim()))
        {
            strSql += " and HRBP_NAME like '" + this.txtHrbp.Text.Trim() + "' ";
        }
        if (!string.IsNullOrEmpty(this.HidHrbp.Value.Trim()))
        {
            strSql += "and HRBP like '" + this.HidHrbp.Value.Trim() + "' ";
        }
 
        DataTable table = DbHelperSQL.Query(strSql).Tables[0];
        GridView1.DataSource = table;
        GridView1.DataBind();
 
        RecCount.Text = GridView1.PageCount.ToString();
 
        PageIn.Text = (GridView1.PageIndex + 1).ToString();
        RowCounts.Text = table.Rows.Count.ToString();
        PageIndex.Text = (GridView1.PageIndex + 1).ToString();
    }
 
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        BindGridView();
    }
    protected void btnClear_Click(object sender, EventArgs e)
    {
        this.txtDept.Text = "";
        this.HidDept.Value = "";
        this.txtHrbp.Text = "";
        this.HidHrbp.Value = "";
        BindGridView();
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        string dept = this.HidDept.Value.Trim();
        string deptname = this.txtDept.Text.Trim();
        string hrbp = this.HidHrbp.Value.Trim();
        string hrbpname = this.txtHrbp.Text.Trim();
        if (dept == "" || hrbp == "")
        {
            ClientScript.RegisterStartupScript(this.GetType(), "msg", "<script language='javascript'>alert('请将信息填写完整!')</script>");
        }
        else
        {
            string strSql = "insert into HRSPECIAL_Repair(DEPT,DEPT_NAME,HRBP,HRBP_NAME) values('" + dept + "','" + deptname + "','" + hrbp + "','" + hrbpname + "')";
            if (DbHelperSQL.ExecuteSql(strSql) > 0)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "msg", "<script language='javascript'>alert('保存成功')</script>");
                this.txtDept.Text = "";
                this.HidDept.Value = "";
                this.txtHrbp.Text = "";
                this.HidHrbp.Value = "";
                BindGridView();
            }
        }
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        BindGridView();
    }
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        BindGridView();
    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        
        string dept = ((HiddenField)GridView1.Rows[e.RowIndex].Cells[0].Controls[1]).Value;
        string deptName = ((TextBox)GridView1.Rows[e.RowIndex].Cells[0].Controls[3]).Text;  
        
        string hrbp = ((HiddenField)GridView1.Rows[e.RowIndex].Cells[1].Controls[3]).Value;
        string hrbpName = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[1]).Text;
 
        string guid = GridView1.DataKeys[e.RowIndex].Value.ToString();
  
        if (dept == "" || hrbp == "")
        {
            ClientScript.RegisterStartupScript(this.GetType(), "msg", "<script language='javascript'>alert('请将信息填写完整!')</script>");
        }
        else
        {
            string strSql = "update HRSPECIAL_Repair set DEPT='" + dept + "',DEPT_NAME='" + deptName + "',HRBP='" + hrbp + "',HRBP_NAME='" + hrbpName + "' where GUID='" + guid + "'";
            if (DbHelperSQL.ExecuteSql(strSql) > 0)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "msg", "<script language='javascript'>alert('保存成功')</script>");
                GridView1.EditIndex = -1;
                BindGridView();
            }
        }
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string guid = GridView1.DataKeys[e.RowIndex].Value.ToString();
        string strSql = "delete from HRSPECIAL_Repair where GUID='" + guid + "'";
        if (DbHelperSQL.ExecuteSql(strSql) > 0)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "msg", "<script language='javascript'>alert('删除成功')</script>");
            BindGridView();
        }
    }
 
    //分页及数据显示
    protected void goindex_Click(object sender, EventArgs e)
    {
        int currentPage = 0;
        try
        {
            currentPage = int.Parse(PageIndex.Text) - 1;
        }
        catch
        {
            return;
        }
 
        if (currentPage < 0)
        {
            return;
        }
        this.GridView1.PageIndex = int.Parse(PageIndex.Text) - 1;
        BindGridView();
    }
}

 

 

前台页面:

 

 

<head runat="server">
    <title></title>
    <script type="text/javascript">
 
        function SelUser(FormType) {
            var win = null;
            var tp = (window.screen.availHeight - 500) / 2;
            var lf = (window.screen.availWidth - 750) / 2;
            if (win != null) {
                try {
                    win.close();
                }
                catch (e2) {
                    win = null;
                }
            }
 
            win = window.open("../../com/SelectUser.aspx?FormType=" + escape(FormType), null, "scrollbars=yes, resizable=no, toolbar=no, menubar=no, location=no, directories=no,width=750,height=500,top=" + tp + ",left=" + lf);
        }
 
        function CheckDept(FormType) {
            var win = null;
            var tp = (window.screen.availHeight - 500) / 2;
            var lf = (window.screen.availWidth - 750) / 2;
            if (win != null) {
                try {
                    win.close();
                }
                catch (e2) {
                    win = null;
                }
            }
            win = window.open("../../com/selDept.aspx?FormType=" + escape(FormType) + "", null, "scrollbars=yes, resizable=no, toolbar=no, menubar=no, location=no, directories=no,width=750,height=400,top=" + tp + ",left=" + lf);
        }
 
 
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <fieldset>
        <legend>查询区域</legend>
        <table width="100%" border="0" cellpadding="1" cellspacing="1">
            <tr>
                <td class="SilverTr" align="left" style="width: 20%;">
                    部门:
                </td>
                <td style="width: 20%">
                    <asp:TextBox ID="txtDept" runat="server"></asp:TextBox>
                    <asp:HiddenField ID="HidDept" runat="server" />
                    <input type="button" id="btnDept" value="..." οnclick="CheckDept('deptcheck')" />
                </td>
                <td class="SilverTr" align="left" style="width: 20%;">
                    HRBP:
                </td>
                <td style="width: 20%">
                    <asp:TextBox ID="txtHrbp" runat="server"></asp:TextBox>
                    <asp:HiddenField ID="HidHrbp" runat="server" />
                    <input type="button" id="btnHrbp" value="..." οnclick="SelUser('PM_Hrbp')" />
                </td>
                <td>
                    <asp:Button ID="btnSearch" runat="server" Text="查询" OnClick="btnSearch_Click" />
                    <asp:Button ID="btnClear" runat="server" Text="重置" OnClick="btnClear_Click" />
                    <asp:Button ID="btnSave" runat="server" Text="保存" OnClick="btnSave_Click" />
                </td>
            </tr>
        </table>
    </fieldset>
    <fieldset>
        <legend>显示区域</legend>
        <div style="padding-right: 0px; overflow-y: auto; padding-left: 0px; scrollbar-face-color: black;
            padding-bottom: 0px; scrollbar-highlight-color: #d4d0c8; overflow: auto; width: 100%;
            scrollbar-shadow-color: #919192; scrollbar-3dlight-color: #d4d0c8; line-height: 100%;
            scrollbar-arrow-color: #919192; padding-top: 0px; scrollbar-track-color: #d4d0c8;
            scrollbar-darkshadow-color: #d4d0c8; letter-spacing: 1pt; height: auto;">
        </div>
        <div>
            共条<asp:Label ID="RowCounts" runat="server"></asp:Label>数据 第<asp:Label ID="PageIn"
                runat="server"></asp:Label>/<asp:Label ID="RecCount" runat="server" />页
            <asp:TextBox ID="PageIndex" runat="server" Width="25px"></asp:TextBox>
            <asp:Button ID="goindex" runat="server" Text="GO" OnClick="goindex_Click" />
        </div>
        <div>
            <asp:GridView ID="GridView1" runat="server" PageSize="20" BackColor="#CCCCFF" AutoGenerateColumns="False"
                Width="100%" EmptyDataText="No Data!" DataKeyNames="GUID" EnableModelValidation="True"
                OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowDeleting="GridView1_RowDeleting"
                OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating">
                <Columns>
                    <asp:TemplateField HeaderText="部门">
                        <EditItemTemplate>
                            <asp:HiddenField ID="HidDEPT" runat="server" Value='<%# Eval("DEPT") %>' />
                            <asp:TextBox ID="txtDEPT" runat="server" Text='<%# Eval("DEPT_NAME") %>'></asp:TextBox>
                            <input id="btnDEPT" type="button" value="..." οnclick='var type= "deptname-" + document.all[this.sourceIndex - 1].name;CheckDept(type);' />
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Eval("DEPT_Name") %>'></asp:Label>
                        </ItemTemplate>
                        <HeaderStyle HorizontalAlign="Center" Width="40%" />
                    
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="HRBP">
                        <EditItemTemplate>
                        <asp:TextBox ID="txtHRBP" runat="server" Text='<%# Eval("HRBP_Name") %>'></asp:TextBox>
                            <asp:HiddenField ID="HidHRBP" runat="server" Value='<%# Eval("HRBP") %>' />
                            
                            <input id="btnHRBP" type="button" value="..." οnclick='var type= "hrbpname-" + document.all[this.sourceIndex - 1].name;SelUser(type);' />
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label2" runat="server" Text='<%# Eval("HRBP_NAME") %>'></asp:Label>
                        </ItemTemplate>
                        <HeaderStyle HorizontalAlign="Center" Width="40%" />
                     
                    </asp:TemplateField>
                    <asp:CommandField HeaderText="编辑" ShowEditButton="True">
                        <HeaderStyle HorizontalAlign="Center" />
                        <ItemStyle HorizontalAlign="Center" Width="10%" />
                    </asp:CommandField>
                    <asp:CommandField HeaderText="删除" ShowDeleteButton="True">
                        <HeaderStyle HorizontalAlign="Center" />
                        <ItemStyle HorizontalAlign="Center" Width="10%" />
                    </asp:CommandField>
                </Columns>
                <PagerSettings FirstPageText="首页" LastPageText="尾页" NextPageText="下一页" PreviousPageText="上一页"
                    Mode="NextPreviousFirstLast" />
                <RowStyle BackColor="#EFF3FB" />
                <PagerStyle ForeColor="Black" HorizontalAlign="Center" />
                <EditRowStyle BackColor="#2461BF" />
                <HeaderStyle BackColor="#EEF3F6" />
                <AlternatingRowStyle BackColor="White" />
            </asp:GridView>
        </div>
    </fieldset>
    </form>
</body>
</html>

<script type="text/javascript"> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。、可私 6信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 、可私信6博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 、可私信6博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值